Search code examples
.net-coreserilog

Dot net core Serilog If there any way not to show errors in Console and shows only information and warnings


Console application project .. In my code I want to hide errors from console, How Can I do that without hide information and warnings

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));

Solution

  • 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));