Log4Net:枚举GlobalContext属性吗? [英] Log4Net: Enumerating GlobalContext properties?
问题描述
我正在尝试将Loggly附加程序实用程序用于log4net.
我发现它们的代码正在通过ThreadContext
属性枚举,并将它们附加到通过有线发送到loggly服务的有效负载中.好主意!但是,同一功能未应用于GlobalContext
属性.弄清楚这是他们的错,我尝试通过GlobalContext
属性枚举并将它们也添加到有效负载中.
I'm trying to utilize the Loggly appender utility for log4net.
I've found that their code is enumerating through the ThreadContext
properties and appending them to the payload getting sent over the wire to the loggly service. Good idea! However, the same feature is not being applied to the GlobalContext
properties. Figuring this was a miss on their part I tried my hand at enumerating through the GlobalContext
properties and adding these to the payload as well.
但是,这已被证明是一个问题.在访问ThreadContext
属性时,似乎没有任何方法可以访问键和关联的值.
However, this has proven to be a problem. There doesn't appear to be any way to access the keys and associated values as the ThreadContext
properties are accessed.
如何枚举GlobalContext
属性?
推荐答案
我看到的唯一方法是检索全局上下文的属性类(返回返回GlobalContextProperties
类的GlobalContext.Properties
)并获取GetReadOnlyProperties()
通过反射返回.拥有ReadOnlyPropertiesDictionary
后,您就可以迭代键和值
The only way I see would be to retrieve the properties class for the global context (GlobalContext.Properties
which returns a GlobalContextProperties
class) and get the ReadOnlyPropertiesDictionary
returned by the internal method GetReadOnlyProperties()
through reflection. Once you have the ReadOnlyPropertiesDictionary
you can iterate on keys and values
根据我的见解,ThreadContext
具有或多或少相同的机制,因此您可以以ThreadContext
枚举为例,将其移植到GlobalContext
.
From what I see the ThreadContext
has more or less the same mechanism so you could take example on the ThreadContext
enumeration to port it to the GlobalContext
.
这篇关于Log4Net:枚举GlobalContext属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!