简体   繁体   中英

ASP.NET Core 2.0 Custom LoggingProvider filter in appsettings.json

In asp.net core it is possible to register the different logging providers:

services.AddLogging(builder => builder
            .AddConsole()
            .AddDebug();

Then configure inside appsetttings.json:

{
    "Logging": {
        "IncludeScopes": false,
        "Console": {
            "LogLevel": {
                "Default": "Warning"
             }
         }
     }
 }

But how do I configure the log level for a custom logging provider:

builder.Services.AddSingleton<ILoggerProvider,MyLoggerProvider>

What should be added to appsettings.json and what should be done in code? I am guessing something like:

{
    "Logging": {
        "IncludeScopes": false,
        "Console": {
            "LogLevel": {
                "Default": "Warning"
             }
         }
         "?":{
             "LogLevel": {
                "Default": "Debug"
             } 
         }
     }
 }

But what goes in "?" if indeed this is the correct approach?

You can use the ProviderAlias attribute on your CustomLoggerProvider class and add that Alias to appsettings.json file.

[ProviderAlias("MyLogger")]
  public class MyLoggerProvider



  "MyLogger":{
         "LogLevel": {
            "Default": "Debug"
         } 
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM