Serilog - AppSettings MinLevel 不工作 [英] Serilog - AppSettings MinLevel not working

查看:102
本文介绍了Serilog - AppSettings MinLevel 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接我的接收器,似乎我的滚动文件接收器没有记录我的调试消息(仅信息及以上).我的配置有问题吗?

I am trying to wire up my sinks and it seems for my rolling file sink my debug messages are not being logged (only info and above). Is my configuration wrong?

<!-- Serilog Configuration -->
<add key="serilog:using:Email" value="Serilog.Sinks.Email" />

<!-- Configure Serilog Email Sink -->
<add key="serilog:write-to:Email" />
<add key="serilog:write-to:Email.mailServer" value="***" />
<add key="serilog:write-to:Email.toEmail" value="***" />
<add key="serilog:write-to:Email.fromEmail" value="***" />
<add key="serilog:write-to:Email.mailSubject" value="Comply360 Portal Endpoint (DEV)" />
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Warning" />
<add key="serilog:write-to:Email.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

<!-- Configure Serilog RollingFile Sink -->
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\comply360-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

推荐答案

RollingFile 接收器配置本身没有任何错误" - 它只会记录日志级别为 Debug 的消息 或更高版本(即它不会按照您的意图记录 Verbose 消息).

There is nothing "wrong" with your RollingFile sink config per se - it will only log messages with log level Debug or above (i.e. it will not log Verbose messages) as you intended.

但是,一般来说,Serilog 的最低日志级别是Information,因此它甚至不会发送到您的接收器.

However, the minimum log level for Serilog in general is Information, so it doesn't even send to your sink.

您需要将 Serilog 的默认最低级别更改为至少 Debug,在您的情况下:

You need to change Serilog's default minimum level to at least Debug, in your case:

<add key="serilog:minimum-level" value="Debug" />

您的最终配置应如下所示:

Your final config should look like this:

<add key="serilog:minimum-level" value="Debug" />
<add key="serilog:write-to:RollingFile" />
<add key="serilog:write-to:RollingFile.restrictedToMinimumLevel" value="Debug" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\log-portal-{Date}.txt" />
<add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] [{CorrelationId}] {Message}{NewLine}{Exception}" />

<小时>

当然,如果您以后决定添加任何记录 Verbose 消息及以上消息的接收器,您也需要将最低级别更改为 Verbose.


Of course, if you later decide to add any sink that logs Verbose messages and above, you'll need to change the minimum-level to Verbose too.

serilog:minimum-level 应该始终是所有接收器中的最低级别.

i.e. serilog:minimum-level should always be the lowest level from all of your sinks.

这篇关于Serilog - AppSettings MinLevel 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆