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

Add Alias attribute to NLogLoggerProvider #206

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

leewadhams
Copy link
Contributor

Added the Microsoft.Extensions.Logging.ProviderAliasAttribute to the NLogLoggerProvider to enable it to be used Logging Configuration instead of having to supply the full name of the provider class.

@304NotModified
Copy link
Member

Hi! Could you please give an configuration example how to use this? Thanks!

@leewadhams
Copy link
Contributor Author

leewadhams commented Apr 4, 2018

The configuration would be like that of the example in the Microsoft docs on Log Filtering with the addition of specifying filters for the NLog Logging Provider using the alias NLog instead of having to specify the full name NLog.Extensions.Logging.NLogLoggerProvider e.g.

public static void Main(string[] args)
{
    var webHost = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
            config.AddEnvironmentVariables();
        })
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddNLog();
        })
        .UseStartup<Startup>()
        .Build();

    webHost.Run();
}
{
  "Logging": {
    "IncludeScopes": false,
    "Console": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Critical"
      }
    },
    "Debug": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Critical"
      }
    },
    "NLog": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Critical"
      }
    },
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

It follows the same pattern as the built in Logger Providers such as DebugLoggerProvider

@304NotModified
Copy link
Member

@304NotModified 304NotModified added this to the 1.0.1 milestone Apr 5, 2018
@leewadhams
Copy link
Contributor Author

@304NotModified yes that still works. The example you gave is just a generic filter across all LoggerProviders. All this attribute does is gives us a "friendly" name if we want to apply filters in config specifically for the NLog Logger Provider.

@304NotModified 304NotModified merged commit aad213b into NLog:master Apr 6, 2018
@304NotModified
Copy link
Member

Thanks! Nice improvement!

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

Successfully merging this pull request may close these issues.

None yet

2 participants