Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout processinfo with support for custom Format-string #1752

Merged
merged 2 commits into from Nov 13, 2016

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Nov 8, 2016

Makes it possible to make a filename like this:

fileName="c:/temp/Log/test1-${processinfo:property=StartTime:format=yyyy-MM-dd_HHmmss}.log"


This change is Reviewable

@codecov-io
Copy link

codecov-io commented Nov 8, 2016

Current coverage is 80% (diff: 100%)

Merging #1752 into master will increase coverage by <1%

@@             master      #1752   diff @@
==========================================
  Files           274        274          
  Lines         17422      17424     +2   
  Methods        2741       2742     +1   
  Messages          0          0          
  Branches       1966       1966          
==========================================
+ Hits          13974      13992    +18   
+ Misses         3005       2987    -18   
- Partials        443        445     +2   

Sunburst

Powered by Codecov. Last update 71c8b60...470cd42

@@ -81,6 +89,19 @@ protected override void InitializeLayoutRenderer()
}

this.process = Process.GetCurrentProcess();

if (!string.IsNullOrEmpty(Format))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about value.ToStringWithOptionalFormat(...) ? (in class FormatHelper)

@304NotModified
Copy link
Member

Good idea! But I think all those reflection isn't needed :) See code comment

@snakefoot
Copy link
Contributor Author

snakefoot commented Nov 8, 2016

Good catch. I have change the logic to use FormatHelper.ToStringWithOptionalFormat, and it still flies.

builder.Append(Convert.ToString(this.propertyInfo.GetValue(this.process, null), formatProvider));
var value = this.propertyInfo.GetValue(this.process, null);
if (value != null && this.Format != null)
builder.Append(Internal.FormatHelper.ToStringWithOptionalFormat(value, this.Format, formatProvider));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method already handles null for both. ;)

(and it's an extension method)

So my proposal:

 builder.Append(value.ToStringWithOptionalFormat(this.Format, formatProvider));

@snakefoot
Copy link
Contributor Author

Yes it looks pretty now :)

@304NotModified
Copy link
Member

\0/

I the next major version of NLog we should look how generic handle this for all layoutrenderers. In all cases there should be a Format I think.

@304NotModified
Copy link
Member

304NotModified commented Nov 8, 2016

:lgtm:

@304NotModified 304NotModified added this to the 4.4 milestone Nov 8, 2016
@304NotModified 304NotModified merged commit 8802507 into NLog:master Nov 13, 2016
@304NotModified
Copy link
Member

Merged!

@@ -69,6 +69,12 @@ public ProcessInfoLayoutRenderer()
public ProcessInfoProperty Property { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@304NotModified Think it should just have DefaultValue, and not DefaultParameter. Make PR to remove DefaultParameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please :) and add the other as default. Thx in advance!

@304NotModified
Copy link
Member

@304NotModified 304NotModified added the documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) label Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) feature needs documentation on wiki
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants