Is .NET Core 2.0 logging broken?

后端 未结 4 571
情深已故
情深已故 2020-12-29 02:25

I can\'t seem to get Trace level log information outputted after upgrading to .NET Core 2.0 (+ASP.NET Core 2.0).

In fact, if I do a dotnet new webprojec

4条回答
  •  爱一瞬间的悲伤
    2020-12-29 02:42

    The following structure of appsettings.json seems to work fine:

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

    Taken from https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1

    Also, see what your start up calls are, I find the following works for me:

    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
    
            var logger = new LoggerConfiguration()
                    .MinimumLevel.Information()
                    .WriteTo.Sink(jsonSink)
                    .Enrich.WithExceptionDetails()
                    .CreateLogger();
    
            Log.Logger = logger;
        }
    }
    

提交回复
热议问题