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

Restore IsDebugEnabled check for logging #2783

Merged
merged 1 commit into from Feb 8, 2022
Merged

Conversation

WilliamBZA
Copy link
Member

Re-adds the IsDebugEnabled check that was removed in #2775.

The explicit call to builder.SetMinimumLevel(loggingSettings.ToHostLogLevel()); sets the logging level correctly between the instances of NServiceBus.Extensions.Hosting.DeferredLogger and NServiceBus.Extensions.Hosting.Logger which means the fix for #2775 is no longer required.

Copy link
Member

@ramonsmits ramonsmits left a comment

Choose a reason for hiding this comment

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

+1 for restoring the if(logger.IsDebugEnabled on the log entries that use string interpolation.

Regarding builder.SetMinimumLevel(loggingSettings.ToHostLogLevel()), that is required as AFAIK the NLog configuration is independant on the logging extensions. For example, NLog verbosity could be set to Trace, and logging extensions to Info meaning logger.Debug would not log anything.

Reason this is different for the DeferredLogger is that only at the start IsDebugEnabled likely returns true until the endpoint is started if NLog was configured to only log Info or more severe. The items temporarily stored in the deferredlogger instance will be flushed but none of them will be written.

Maybe @danielmarbach can comment on my deferred logger assumptions.

I'm not really sure how the NServiceBus hosting extensions work. I do think there is a code smell, the deferred logger instanced shouldn't be needed due the way how start tasks currently work it is required but IMHO should be improved. Currently you could for example not cache IsDebugEnabled in a readonly bool IsDebugEnabled = logger.IsDebugEnabledto JIT compile all theseif`'s from the runtime code.

Small comment on the PR, these 2 changes are independant (IsDebugEnabled vs init) and maybe consider 2 PR's?

@WilliamBZA WilliamBZA merged commit e57f79c into master Feb 8, 2022
@WilliamBZA WilliamBZA deleted the add-isdebug-check branch February 8, 2022 08:17
@WilliamBZA WilliamBZA added this to the 4.21.5 milestone Feb 8, 2022
WilliamBZA added a commit that referenced this pull request Feb 11, 2022
@adamralph adamralph changed the title ReAdd IsDebugEnabled check for logging Restore IsDebugEnabled check for logging Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants