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

Adds support for NLog to application logging #1087

Merged
merged 15 commits into from
May 25, 2022
Merged

Conversation

jaffinito
Copy link
Member

@jaffinito jaffinito commented May 16, 2022

Description

  • Adds support got NLog version 4 and 5 for application logging - metrics, forwarding, and local decorating
  • Updated Microsoft.Extensions.Logging support to exclude NLog from decorating since NLog support automatic decorating of local logs
  • Includes NLog tests for all logging integration tests on several versions
  • MSI changes to include NLog

Author Checklist

Reviewer Checklist

  • Perform code review
  • Pull request was adequately tested (new/existing tests, performance tests)
  • Review Changelog

@jaffinito jaffinito added the feature request To tag an issue after triage that is a feature instead of TD label May 16, 2022
@jaffinito jaffinito added this to the Logging Initiative - NLog milestone May 16, 2022
Copy link
Contributor

@JcolemanNR JcolemanNR left a comment

Choose a reason for hiding this comment

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

Reviewed in pairing, and this looks ready to ship!

{
var logconsole = new ConsoleTarget();

NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(logconsole, LogLevel.Debug);
Copy link

@snakefoot snakefoot May 24, 2022

Choose a reason for hiding this comment

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

Maybe use isolated NLog.LogFactory like this:

var logFactory = new NLog.LogFactory();
var logConfig  = new NLog.Config.LoggingConfiguration();
var logConsole = new ConsoleTarget();
if (layoutOverride != null)
      logConsole = layoutOverride;
logConfig.AddTarget("console", logConsole);
logConfig.LoggingRules.Add(new NLog.Config.LoggingRule("*", NLog.LogLevel.Trace, logConsole));
logFactory.Configuration = logConfig;
return logFactory.GetLogger("LoggingTest");

Then ConfigureJsonLayoutAppenderForDecoration() can provide its JsonLayout as layoutOverride.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for this! I updated the adapter to setup the log this and all the tests passed!

Copy link
Member

@michaelgoin michaelgoin left a comment

Choose a reason for hiding this comment

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

Looks pretty solid to me. Some minor comments that don't need to be addressed.

Would recommend the testing on the actual 5.0 version in this or a follow-up PR.

I did notice we access an internal "Message" property taht seems like we are assuming can never be null. Which may be the case but seems maybe slightly less guaranteed than a "FormattedMessage" without looking at the code. Just calling out to make sure that was known given we do string appending.

@JcolemanNR JcolemanNR changed the title Adds support got NLog to application logging Adds support for NLog to application logging May 24, 2022
@jaffinito jaffinito merged commit 6ec089a into main May 25, 2022
@jaffinito jaffinito deleted the application-logging-nlog branch May 25, 2022 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request To tag an issue after triage that is a feature instead of TD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants