【问题标题】:Can NLog's variables be modified programatically if Common.Logging is in use?如果正在使用 Common.Logging,是否可以通过编程方式修改 NLog 变量?
【发布时间】:2016-03-22 21:05:34
【问题描述】:

我有一个 NLog 变量,我想在运行时在 C# 中设置它的值:

LogManager.Configuration.Variables["MyVarName"] = DetermineMyVarValue();

但那是 NLog 代码。我正在考虑使用 Common.Logging 而不是直接使用 NLog。我看不到如何通过 Common.Logging 做这种事情。有什么办法吗?

或者,也许有一种方法可以在运行时从 NLog 配置文件本身中执行此操作?所以 Common.Logging 可以回避?例如,类似:

<variable name="MyVarName" value="MyStaticClass.DetermineMyVarValue()"/>

最好在第一次使用时调用该函数一次,而不是每次引用变量时都调用该函数?

【问题讨论】:

    标签: c# .net logging nlog common.logging


    【解决方案1】:

    还没有找到直接的答案,但我发现了一些对我的目的来说足够好的东西,所以我在这里提一下,以防将来可能对某人有所帮助:

    我只是写了custom layout renderer而不是变量,这很简单。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2011-01-08
      • 2019-07-13
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多