logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Arnott <andrewarn...@gmail.com>
Subject Re: ThreadLogicalContext not actually following logical threads
Date Mon, 28 Nov 2011 17:35:41 GMT
The documentation is poor, I agree.  I had to stumble around quite a bit
before I figured out how to use it properly myself.  I believe the
difference may be that CallContext.*Logical*SetData requires the value to
be serializable, so that it can be cloned and applied to other threads,
perhaps even in separate appdomains.

This sounds like an area that log4net can improve then.  I'm not sure why
log4net claims to follow the logical thread when apparently it doesn't.

The good news is that in the absence of built-in support from log4net, I've
engineered a solution of my own by controlling the
HostExecutionContextManager in my AppDomain.  Whenever the logical thread
forks (i.e. threadpool use, c# 5 async keyword, etc.) my code "captures"
the current context stack from log4net and applies that stack to the new
thread, and "reverts" that change when the target thread has completed its
work for that call.

Pretty cool stuff, but it would be cooler if log4net had it built-in.
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death
your right to say it." - S. G. Tallentyre

On Mon, Nov 28, 2011 at 8:52 AM, Stefan Bodewig <bodewig@apache.org> wrote:

> On 2011-11-27, Andrew Arnott wrote:
> > I am successfully using CallContext.LogicalSetData myself for other
> logical
> > thread tracking purposes in my application so I have reason to believe it
> > works -- I just don't know why log4net isn't working.  Any ideas?
> LogicalThreadContext uses SetData rather than LogicalSetData (the latter
> isn't available in .NET 1.x).  Based on no knowledge other than MSDN it
> is unclear to me what SetData would do if it didn't work on the logical
> thread, but there probably is a reason for having two methods.
> Stefan

View raw message