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

Make a doc for the LoggerMessage.DefineScope pattern #2810

Closed
BrennanConroy opened this issue Feb 21, 2017 · 9 comments
Closed

Make a doc for the LoggerMessage.DefineScope pattern #2810

BrennanConroy opened this issue Feb 21, 2017 · 9 comments
Labels
Milestone

Comments

@BrennanConroy
Copy link
Member

We should document the low allocation logging pattern that uses LoggerMessage.DefineScope and LoggerMessage.Define as seen here https://github.com/aspnet/KestrelHttpServer/blob/b41c4078bdbbf2b2413fe13922a64552ed1177b6/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Infrastructure/KestrelTrace.cs and https://github.com/aspnet/Mvc/blob/624909763bf762c4448955d00eef1649737df8d6/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorLoggerExtensions.cs

@glennc
Copy link
Contributor

glennc commented Feb 23, 2017

I think some guidance around the implications of mixing something like string interpolation and formatters will be useful to add as well.

@guardrex
Copy link
Collaborator

@Rick-Anderson

  • Would you like this as a sub-topic to fundamentals/logging.md in the TOC?
  • Title? 🏎️ High-performance logging with LoggerMessage in ASP.NET Core 🏎️

@Rick-Anderson
Copy link
Contributor

@guardrex sounds good. cc @scottaddie

@guardrex
Copy link
Collaborator

@Rick-Anderson @scottaddie Proposal for this topic ...

Title: High-performance logging with LoggerMessage in ASP.NET Core
TOC: sub-topic to fundamentals/logging.md

Outline

  • Introduction
    • LoggerMessage feature description (1-2 sentences)
    • Sample link
  • Describe LoggerMessage.Define and LoggerMessage.DefineScope
  • Illustrate LoggerMessage.Define using the sample
  • Illustrate LoggerMessage.DefineScope using the sample

@Rick-Anderson
Copy link
Contributor

@BrennanConroy @glennc can you review the outline? LGTM.

@BrennanConroy
Copy link
Member Author

👍

@guardrex
Copy link
Collaborator

guardrex commented Oct 30, 2017

@glennc @BrennanConroy

TL;DR

This ...

.ConfigureLogging((hostingContext, logging) =>
{
    logging.AddConsole(options => options.IncludeScopes = true);
})

... is absolutely required to make scopes work? If so, then why is the IncludeScopes setting in the templates?

Rubber duck

Need a head-check on scopes config behavior:

  1. I have IncludeScopes set to true in appsettings files.
  2. I see that the logging config is handled by WebHost's CreateDefaultBuilder: https://github.com/aspnet/MetaPackages/blob/dev/src/Microsoft.AspNetCore/WebHost.cs#L178
    logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

or I assumed that config would take care of it here ...

https://github.com/aspnet/Logging/blob/1ec418937ddb6bbcc83653e90b89285da9eb2a62/src/Microsoft.Extensions.Logging.Console/ConfigurationConsoleLoggerSettings.cs#L27-L35

... but scopes aren't active unless I explicitly set ...

.ConfigureLogging((hostingContext, logging) =>
{
    logging.AddConsole(options => options.IncludeScopes = true);
})

RE: ...

https://github.com/aspnet/Logging/blob/1ec418937ddb6bbcc83653e90b89285da9eb2a62/src/Microsoft.Extensions.Logging.Console/ConfigurationConsoleLoggerSettings.cs#L27

I wondered if that should be ...

var value = _configuration["Logging:IncludeScopes"];

... but even moving "IncludeScopes" up one level doesn't work ...

{
  "IncludeScopes": true,
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

No 🎲 🎲 with this either ...

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    },
    "Console": {
      "IncludeScopes": true
    }
  }
}

@BrennanConroy
Copy link
Member Author

I believe IncludeScopes isn't working from configuration files in 2.0.0, but has been fixed in latest dev. Although it now lives under the specific logger, so your last example should work in 2.1.0-*

@guardrex
Copy link
Collaborator

@BrennanConroy Thanks. I'll make a small modification to the Logging topic to compensate for the time being. The current language doesn't call it out clearly.

@scottaddie @Rick-Anderson I'll add the update for the Logging topic to the LoggerMessage PR, which should be up soon. The sample is almost finished, and the topic is a one-day write-up. Should have it Tuesday ... Wednesday at the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants