Skip to content

Added WithProperty and SetProperty on Logger#3298

Merged
304NotModified merged 3 commits intoNLog:devfrom
snakefoot:LoggerWithPropertyVer2
Apr 16, 2019
Merged

Added WithProperty and SetProperty on Logger#3298
304NotModified merged 3 commits intoNLog:devfrom
snakefoot:LoggerWithPropertyVer2

Conversation

@snakefoot
Copy link
Copy Markdown
Contributor

@snakefoot snakefoot commented Apr 10, 2019

Logger - WithProperty for adding Logger specific properties that are included for all LogEvents

Different attempt of implementing #2496

Still trying to resolve #528


This change is Reviewable

@snakefoot snakefoot force-pushed the LoggerWithPropertyVer2 branch from b44e2a2 to 84304df Compare April 10, 2019 20:49
@snakefoot snakefoot force-pushed the LoggerWithPropertyVer2 branch from 84304df to 47f861d Compare April 10, 2019 20:56
@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 10, 2019

Codecov Report

Merging #3298 into dev will increase coverage by <1%.
The diff coverage is 85%.

@@          Coverage Diff           @@
##             dev   #3298    +/-   ##
======================================
+ Coverage     80%     80%   +<1%     
======================================
  Files        356     356            
  Lines      28077   28123    +46     
  Branches    3739    3753    +14     
======================================
+ Hits       22485   22551    +66     
+ Misses      4488    4481     -7     
+ Partials    1104    1091    -13

@snakefoot snakefoot force-pushed the LoggerWithPropertyVer2 branch from 185ea00 to 47f861d Compare April 13, 2019 21:16
@304NotModified
Copy link
Copy Markdown
Member

Thanks for the PR,

but i'm afraid it won't change the NLog API viewpoint, mentioned in #2496 (comment)?

@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 14, 2019 via email

@304NotModified
Copy link
Copy Markdown
Member

If we also add SetProperty, next to WithProperty, do you think that is OK? (from viewpoint API design)

@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 14, 2019

@304NotModified Added a SetProperty method for updating the current Logger object-instance.

@304NotModified
Copy link
Copy Markdown
Member

Cool!

@304NotModified
Copy link
Copy Markdown
Member

Need to check it in depth, but I think I will merge it soon :)

@304NotModified 304NotModified self-assigned this Apr 14, 2019
@304NotModified 304NotModified self-requested a review April 14, 2019 18:06
@304NotModified 304NotModified changed the title Logger WithProperty Addede WithProperty and SetProperty on Logger Apr 14, 2019
Comment thread src/NLog/Logger.cs Outdated
Comment thread src/NLog/Logger.cs Outdated
Comment thread src/NLog/Logger.cs Outdated
Comment thread src/NLog/Logger.cs
Comment thread src/NLog/LoggerImpl.cs
@304NotModified 304NotModified changed the title Addede WithProperty and SetProperty on Logger Added WithProperty and SetProperty on Logger Apr 14, 2019
@304NotModified 304NotModified added this to the 4.6.3 milestone Apr 14, 2019
@snakefoot snakefoot force-pushed the LoggerWithPropertyVer2 branch from e910771 to 7585208 Compare April 14, 2019 21:10
Copy link
Copy Markdown
Member

@304NotModified 304NotModified left a comment

Choose a reason for hiding this comment

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

Thanks!

Is this safe for 4.6.3?

Comment thread src/NLog/Logger.cs
{
if (IsEnabled(logEvent.Level))
var targetsForLevel = IsEnabled(logEvent.Level) ? GetTargetsForLevel(logEvent.Level) : null;
if (targetsForLevel != null)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this a performance tweak?

Comment thread src/NLog/Logger.cs
@304NotModified 304NotModified removed their assignment Apr 16, 2019
@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 16, 2019 via email

@304NotModified
Copy link
Copy Markdown
Member

304NotModified commented Apr 30, 2019

@304NotModified 304NotModified added the documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) label Apr 30, 2019
@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 30, 2019

Updated the docs a little so the difference between WithProperty and SetProperty is clearer. Making the trap-door hidden in SetProperty a little more visible.

@304NotModified
Copy link
Copy Markdown
Member

304NotModified commented Apr 30, 2019

It's not a trap but a feature :)

@304NotModified
Copy link
Copy Markdown
Member

Updated it with a 2nd log. The set is really useful is some cases (e.g when you get more context along the way)

@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 30, 2019

The set is really useful is some cases (e.g when you get more context along the way)

Not when having the global NLog Logger-cache where multiple locations are referencing the same Logger-object, and then one location suddenly decides to call SetProperty (can become a surprise for everyone else)

@304NotModified
Copy link
Copy Markdown
Member

It's not suddenly? It's by (logger) name.

@304NotModified
Copy link
Copy Markdown
Member

Buy anyway, I'm curious when we will implement WithProperties and ClearProperty :p

(Maybe nice with default interfaces - c# 8)

@snakefoot
Copy link
Copy Markdown
Contributor Author

snakefoot commented Apr 30, 2019

It's not suddenly? It's by (logger) name.

Not sure I understand. There is no guarantee that two isolated locations doesn't call GetLogger() with the same name. When one of the isolated locations calls SetProperty then it will affect the other.

Could also be two threads allocating their isolated controller of the same class, then the two controller-classes will be sharing the same Logger-object (Independent of using static Logger-variable, but just because it calls GetCurrentClassLogger). When one thread starts to call SetProperty then it will affect the Logger on the other controller-instance.

That is why I prefer WithProperty because it doesn't give you surprises.

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.

Feature request: define/set variable inside a logger

3 participants