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

Breaking Logging changes and new additions #238

Closed
BrennanConroy opened this issue May 4, 2017 · 1 comment
Closed

Breaking Logging changes and new additions #238

BrennanConroy opened this issue May 4, 2017 · 1 comment

Comments

@BrennanConroy
Copy link
Member

BrennanConroy commented May 4, 2017

Obsolete APIs:

Obsoleted AddProvider on ILoggerFactory

  • All Add*(...) provider extension methods are now obsolete with replacements on Microsoft.Extensions.Logging.LoggerFactory.
  • The AddConsole AddDebug etc. provider extension methods that took a filter or minimum LogLevel are now obsolete

No longer shipping Microsoft.Extensions.Logging.Filter.

First Class Filtering

LoggerFactory now has multiple AddFilter(...) overloads.

Filters use provider names, categories, and log level to filter logs.

There is an AddProvider(string providerName, ILoggerProvider provider) function to add providers with a custom name used for filtering.

Custom provider names are checked first when filtering. then provider full names are checked i.e.
Check Console as the custom name then Microsoft.Extensions.Logging.Console.ConsoleLoggerProvder as the full name.

Old:

var loggerFactory = new LoggerFactory();
loggerFactory = loggerFactory.WithFilter(new FilterLoggerSettings
{
    { "Microsoft", LogLevel.Warning },
    { "System", LogLevel.Error }
});
loggerFactory.AddConsole();

New:

var loggerFactory = new LoggerFactory();
loggerFactory.AddFilter(new Dictionary<string, LogLevel>
{
    { "Microsoft", LogLevel.Warning },
    { "System", LogLevel.Error }
});
loggerFactory.AddConsole();

The AddDebug() AddConsole() etc. methods we provide have predefined custom provider names:

  • Console
  • Debug
  • EventLog
  • AzureAppServices
  • TraceSource
  • EventSource

Configuration

LoggerFactory's constructor can take an IConfiguration and will create filters based on the config:

{
  "Logging": {
    "LogLevel": {
        "System": "Trace",
        "Default": "Warning"
    },
    "Console": {
        "LogLevel": {
          "Microsoft.Extensions": "Warning"
        }
    },
    "CustomProvider": {
      "LogLevel": {
        "System": "Information"
      }
    }
  }
}

The configuration can also be replaced with UseConfiguration on LoggerFactory

The Logging system is configured via IWebHostBuilder.ConfigureLogging

Old:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory factory)
{
    factory.AddConsole();
    factory.AddDebug();
}

New:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .ConfigureLogging(factory =>
        {
            factory.AddConsole();
            factory.AddDebug();
        }
        .etc...

    host.Run();
}

Please use aspnet/Logging#615 for any discussion.

@BrennanConroy BrennanConroy added this to the 2.0.0-preview1 milestone May 4, 2017
@aspnet aspnet locked and limited conversation to collaborators May 4, 2017
@pakrym
Copy link

pakrym commented Jul 11, 2017

This is superseded by #255

@pakrym pakrym closed this as completed Jul 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants