views:

297

answers:

3

I've read in a few places that the log4net threadContext isn't safe to use in an asp.net scenario. Here are a few articles:

http://stackoverflow.com/questions/1066062/log4net-threadcontext-and-global-asax
http://piers7.blogspot.com/2005/12/log4net-context-problems-with-aspnet.html

So my scenario is I want to use the threadContext in a WCF layer hosted within IIS. Is the threadcontext going to be ok? I'm thinking the concurrency mode of "single" would make this ok.

+1  A: 

As Log4net is thread safe I would not expect a problem.

Ian Ringrose
But will WCF execute a request in a single thread correctly? The problem with asp.net was that in some spots a request might jump to different threads so the threadContext in log4net would be useless.
Paul Lemke
@lemkept in most cases by the time it gets to your code WCF will be running the request on a single thread, as the normal case is for WCF to only call one of your methods to process the request. However if you do anything with the request pipeline, I don't know what WCF will do with threading.
Ian Ringrose
A: 

I have used log4net thread context to log the the identity of the user who encountered the error in both asp.net applications and wcf services. I have not run into any issues. This is not a definitive answer but you can always decouple your service from the logging framework and test log4net and the threadcontext. if you encounter any issues remove your thread context logic or plug in a new logging framework with minimal impact to your service logic.

Athens
A: 

I have setup a WCF service, hosted in IIS6, that uses log4net with no issues, regardless of the concurrency mode. Using the threadContext should not be a problem.

The only caveat is that if you load the log4net setting from an external file into the WCF layer, you may have to restart it in IIS to pick up the changes.

Jason W