点网核心Serilog如果有任何方法不在控制台中显示错误并仅显示信息和警告

问题描述 投票:1回答:1

控制台应用程序项目..在我的代码中我想隐藏控制台中的错误,如何在没有隐藏信息和警告的情况下执行此操作

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));
.net-core serilog
1个回答
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));
© www.soinside.com 2019 - 2024. All rights reserved.