Log4Net:枚举GlobalContext属性吗? [英] Log4Net: Enumerating GlobalContext properties?

查看:81
本文介绍了Log4Net:枚举GlobalContext属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆