Serilog不接受StaticFiles,托管和EF Core的MinimumLevel

时间:2019-03-07 12:22:15

标签: asp.net-core entity-framework-core serilog

我正在尝试从ASP.NET Core应用程序中使用Serilog获得干净的日志。要从EF Core清除一些图像请求和db命令,我正在使用下一个过滤器:

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
    .MinimumLevel.Override("System", LogEventLevel.Information)
    .Enrich.FromLogContext()
    .WriteTo.Console(outputTemplate: "{Timestamp:o} [{Level:u3}] [{SourceContext}] {Site}: {Message}{NewLine}")
    .WriteTo.Logger(lc => lc
        .MinimumLevel.Information()
        .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
        .MinimumLevel.Override("System", LogEventLevel.Warning)
        .MinimumLevel.Override("Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware", LogEventLevel.Warning)
        .MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Internal.WebHost", LogEventLevel.Warning)
        .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Error)
        .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Hour, outputTemplate: "{Timestamp:o} [{Level:u3}] [{SourceContext}] {Site}: {Message}{NewLine}")
    )                
    .CreateLogger();

预期结果是具有大量信息的控制台日志和具有较少信息的日志文件,因为对于Microsoft.AspNetCore.StaticFiles.StaticFileMiddlewareMicrosoft.AspNetCore.Hosting.Internal.WebHostMicrosoft.EntityFrameworkCore.Database.Command我设置了一个新的MinimumLevel

实际结果是文件中仍然存在INFORMATIONMicrosoft.AspNetCore.StaticFiles.StaticFileMiddlewareMicrosoft.AspNetCore.Hosting.Internal.WebHost的所有Microsoft.EntityFrameworkCore.Database.Command日志。

0 个答案:

没有答案