简体   繁体   English

如果使用Common.Logging,是否可以通过编程方式修改NLog的变量?

[英]Can NLog's variables be modified programatically if Common.Logging is in use?

I have an NLog variable that I want to set the value of at runtime, in C#: 我有一个NLog变量,我想在C#中设置运行时的值:

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

But that's NLog code. 但这就是NLog代码。 I am considering using Common.Logging rather than directly using NLog. 我正在考虑使用Common.Logging,而不是直接使用NLog。 I do not see how to do this sort of thing through Common.Logging. 我看不到如何通过Common.Logging来执行此类操作。 Is there a way? 有办法吗?

Alternatively, perhaps is there a way to do it at runtime from within the NLog config file itself? 另外,也许有一种方法可以在运行时从NLog配置文件本身内部进行? So that Common.Logging can be sidestepped? 这样可以避免Common.Logging吗? For example, something like: 例如,类似:

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

Preferably where that function would be called once, upon first use, rather than being called every time the variable is referenced? 最好在第一次使用该函数时调用一次,而不是在每次引用变量时调用一次?

Haven't yet found a direct answer, but I have found something that's good enough for my purposes, so I'm mentioning it here in case it might help someone in the future: 尚未找到直接的答案,但是我发现了一些足以满足我目的的东西,因此我在这里提到它,以防将来对某人有所帮助:

Instead of a variable, I just wrote a custom layout renderer , which is pretty straightforward. 我只写了一个自定义布局渲染器 ,而不是变量,这非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM