-
Notifications
You must be signed in to change notification settings - Fork 831
Fixes #1105 - add a static None property to the Logger class #1110
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
Conversation
…exposing a constant SilentLogger instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a couple of nitpicky items from me.
src/Serilog/Core/Logger.cs
Outdated
/// <summary> | ||
/// An <see cref="ILogger"/> instance that efficiently ignores all method calls | ||
/// </summary> | ||
public static ILogger None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get away without a backing property by declaring this as:
public static ILogger None { get; } = new SilentLogger();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries - wasn't sure if you were happy with newer syntax
src/Serilog/Core/Logger.cs
Outdated
static readonly ILogger _noneLogger = new SilentLogger(); | ||
|
||
/// <summary> | ||
/// An <see cref="ILogger"/> instance that efficiently ignores all method calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - missing .
.
Not sure why the AppVeyor CI build has started producing flaky results around |
Maybe some unit tests to add :
|
@tsimbalar - I've addressed your first suggestion. This test
fails. We could modify @nblumhardt - should we do this at all? If so, want it in a separate PR? I've only had a cursory look at LoggerConfiguration.cs and I can think of a couple of approaches - one to check for any methods/setters being called and set a flag so we know not to short-circuit return Logger.None. The other, which is less invasive but may not be quite correct, would be to have Con against doing it... If you really want a silent logger, use the .None property rather than the hacky 'empty configuraton' approach. |
@IanYates oh my bad, I thought that was the actual behavior ... I may be mixed up ... The test that should pass as of now, though, is that |
Great suggestions @tsimbalar 👍 In v1.x, I think this is ready to go; no idea why the CI build is suddenly unhappy, but guess that's something to figure out another day :-) |
What issue does this PR address?
Addresses issue #1105. Replaces PR #1108
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information:
Sorry for the new PR. Given the changes in the old PR were in the completely wrong file, it seemed easier to just close that PR and open a new one.
Issue #1105 asked for an easy way to get at a constant instance of a
SilentLogger
. The original PR added this on theLog
class and slightly adjusted that class' internals to make use of this instance.This new PR instead modifies the
Logger
class to add a staticLogger.None
property that returns the sameSilentLogger
.One new allocation overall. I suspect we can live with that (?). Former PR didn't have that issue. A lazy init sounds like overkill for this but I'm happy to be told I'm wrong.
Only one new unit test - verifying that the property is a silent logger. There's not a lot of machinery or moving parts to verify anymore compared with the earlier PR.
Feedback most welcome. Thanks 💯