且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

serilog 只记录调试、错误和警告日志,而不记录信息

更新时间:2022-06-09 01:34:27

您无法使用 MinimumLevel 作为 @barbsan 注释来实现它.

You cannot achieve it using MinimumLevelas @barbsan comment.

但是您可以使用过滤来处理您的情况.

But you can use filtering for in your case.

过滤器只是对 LogEvent

_logger  = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.File(_filepath)
    .Filter.ByIncludingOnly(isNotInfoLevel)
    .CreateLogger();

在下面的函数中,您可以根据需要添加更多条件

And in below function you can add more conditions if needed

private static bool isNotInfoLevel(LogEvent le)
{
    return le.Level != LogEventLevel.Information;
}

使用ByExclusion排除信息层的另一种方法

Anther way by using ByExcluding to exclude information level

.Filter.ByExcluding((le) => le.Level == LogEventLevel.Information)