gpt4 book ai didi

c# - 如何使用 C# 在 Nlog 中动态禁用特定日志?

转载 作者:行者123 更新时间:2023-11-30 21:56:24 24 4
gpt4 key购买 nike

我试图在 nlog 配置中禁用特定的日志,我这样添加

logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="t" enabled="false"

工作正常。我需要在 C# 中以编程方式进行。

最佳答案

你需要这样的东西:

        // lookup for the rule in NLog config
var rule = LogManager
.Configuration
.LoggingRules
.FirstOrDefault(_ => _.LoggerNamePattern == "*");

// disable the rule
if (rule != null)
rule.DisableLoggingForLevel(LogLevel.Trace);

关于c# - 如何使用 C# 在 Nlog 中动态禁用特定日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31565520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com