log4net.ThreadLogicalContext和log4net.ThreadContext有什么区别 [英] What's the difference between log4net.ThreadLogicalContext and log4net.ThreadContext

查看:131
本文介绍了log4net.ThreadLogicalContext和log4net.ThreadContext有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不理解官方文档中的解释:

I don't understand the explanation in offical document:

逻辑线程可以从一个托管线程跳到另一个托管线程.

ThreadContext和ThreadLogicalContext有什么区别? 有人可以详细说明吗?

What's the different between ThreadContext and ThreadLogicalContext? Can someone elaborate on it?

谢谢.

推荐答案

我应该返回并将其添加到我自己的问题中(Stefan Egli上面链接了)...

I should go back and add this to my own question (that Stefan Egli linked above) ...

据我所知,两者之间几乎没有实际差异.

From what I can tell, there is very little practical difference between the two.

ThreadContext将信息存储在使用Thread.SetData存储的Dictionary中.

ThreadContext stores information in a Dictionary that is stored using Thread.SetData.

ThreadLogicalContext将其信息存储在使用CallContext存储的Dictionary中.

ThreadLogicalContext stores its information in a Dictionary that is stored using the CallContext.

CallContext中存储的信息几乎相同 可访问性作为使用Thread.SetData存储的信息.即,该信息可访问首先存储该信息的线程.

Information stored in the CallContext has almost the same accessibility as information stored using Thread.SetData. That is, the information is accessibli to the thread that stored the information in the first place.

现在,如果ThreadLogicalContext使用CallContext.LogicalSetData(或者如果使用CallContext.SetData存储的Dictionary实现了标记接口IThreadAffinative),那么将会有很大的不同.在这种情况下,可以在同一线程内访问任何存储的信息(LogicalSetData),并将其传递给子线程.另外(逻辑线程流), 信息可以在远程调用和AppDomain之间传输(如果数据是可序列化的).

Now, IF the ThreadLogicalContext used CallContext.LogicalSetData (or if the Dictionary stored using CallContext.SetData implemented the marker interface, IThreadAffinative) then there WOULD be BIG difference. In that case, any information stored (LogicalSetData) could be accessed within the same thread AND is passed to child threads. In addition (flows with the logical thread), the information can flow across remoting calls and across AppDomains (if the data is Serializable).

本来我会插入一些链接,但是我正在使用iPhone工作,所以有点尴尬. Stefan Egli上面发布的链接中有一些很好的链接.

I would have put in some links, but am working from iPhone so is a little awkward. There are some good links in the link that Stefan Egli posted above.

此外,请参阅Jeffrey Richter在9月发布的博客,其中提供有关CallContext.LogicalSetData的文章.我将他的测试程序用作比较CallContext.SetData与CallContext.LogicalSetData与Thread.SetData与[ThreadStatic]的基础.我上次检查是最后一次 他张贴的东西.

Also, look at Jeffrey Richter's blog from September for an article on CallContext.LogicalSetData. I used his test program as a basis for comparing CallContext.SetData vs CallContext.LogicalSetData vs Thread.SetData vs [ThreadStatic]. Last time I checked, it was the last thing he posted.

当我可以轻松访问计算机时,将尝试返回并发布更多链接和/或一些示例代码.

Will try to come back and post more links and/or some sample code when I have easy access to computer.

祝你好运!

这篇关于log4net.ThreadLogicalContext和log4net.ThreadContext有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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