如何在NLog中打开和关闭特定级别的日志记录 [英] How to turn ON and OFF logging for specific levels in NLog
本文介绍了如何在NLog中打开和关闭特定级别的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中使用NLog.我想创建一个开关以打开和关闭特定的记录器级别.
I am using NLog in my application. I want to create a switch in order to turn ON and OFF specific logger levels.
<rules>
<logger name="*" minlevel="Debug" writeTo="f" />
<logger levels="Error,Warn,Fatal,Debug,Info" name="CustomLogger" writeTo="database"/>
</rules>
如何关闭特定记录器级别的记录.我不想将其从下面的行中删除.
How can I turn off logging for a specific logger level. I do not want to remove it from the below line.
<logger levels="Error,Warn,Fatal,Debug,Info" name="CustomLogger" writeTo="database"/>
如何使用以下方法打开和关闭Info
登录:
How to turn Info
logging On and OFF using something like this:
internalLogLevel="Off"
推荐答案
添加最终规则,将日志写入黑洞".将其添加为第一条规则.使用enabled
属性将其关闭/打开.
Add a final rule that writes the logs to a "blackhole". Add this as the first rule. Turn it off/on with the enabled
attribute.
例如要禁用信息"级别,请将其添加为<rules>
的第一条规则:
e.g. To disable the "info" level, add this as first rule of <rules>
:
<logger levels="Info" name="*" writeTo="blackHole" final="true" enabled="true" />
,黑洞目标为<targets>
<target name="blackHole" xsi:type="Null" />
这篇关于如何在NLog中打开和关闭特定级别的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文