点网核心Serilog如果无法在控制台中显示错误并且仅显示信息和警告

时间:2019-03-03 13:02:09

标签: .net-core serilog

控制台应用程序项目..在我的代码中,我想从控制台隐藏错误,如何在不隐藏信息和警告的情况下做到这一点

return logger.MinimumLevel.Verbose()
             .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose)
             .Filter.ByIncludingOnly(Serilog.Filters.Matching.FromSource<Transformer>())
             .Enrich.FromLogContext()
             .WriteTo.Console(LogEventLevel.Information)
             .WriteTo.Async(config => config.File(Path.Combine(logsPath, runId + "-logFileName.log"),
              rollOnFileSizeLimit: true,
             fileSizeLimitBytes: 314572800));

1 个答案:

答案 0 :(得分:1)

return logger.MinimumLevel.Verbose()
         .MinimumLevel.Override("Microsoft", LogEventLevel.Verbose)
         .Filter.ByIncludingOnly(Serilog.Filters.Matching.FromSource<Transformer>())
         .Enrich.FromLogContext()
         .WriteTo.Logger(lc => lc
             .Filter.ByIncludingOnly(le => le.Level == LogEventLevel.Information || le.Level == LogEventLevel.Warning)
             .WriteTo.Console(LogEventLevel.Information))
         .WriteTo.Async(config =>
             config.File(
                 Path.Combine(logsPath, runId + "-logFileName.log"),
                 rollOnFileSizeLimit: true,
                 fileSizeLimitBytes: 314572800));