[ 
https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15640560#comment-15640560
 ] 

Joe commented on LOG4NET-256:
-----------------------------

I'm not sure this is XP related.

The bug description doesn't explain how to repro the problem, but I would 
speculate that an MDC value is being set in an ASP.NET application during 
processing of a web request, and never being reset.  As a result, the value may 
be leaking to other logging events that happen to get the same thread from the 
thread pool.

If this is correct a solution would be (whether it's an MDC value or a 
ThreadContext value:

    try
    {
        read and save previous valiue
        set MDC or ThreadContext value
        ,,, do work ...
    }
    finally
    {
        reset MDC or ThreadContext value to saved value
    }

In my logging façade, I have a PushThreadContext method that returns an 
instance of an IDisposable class that handles the save/restore, so that this 
becomes:

    using(MyFacade.PushThreadContext(key, value))
    {
        ... do work ...
    } // previous value restored here


> log4net With MDC is not exactly threadsafe?
> -------------------------------------------
>
>                 Key: LOG4NET-256
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-256
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.10
>         Environment: Windows Server 2003, Windows XP
>            Reporter: MK Pandey
>             Fix For: 1.2 Maintenance Release
>
>         Attachments: bug detals mail.jpg
>
>
> Hi All, 
> Our situation is that we are using MDC values (ex, transID) to set additional 
> values which is used across multiple classes to identify the transaction. 
> We have one LogHelper class which creates private static instance of the as 
> below: 
> log4net.ILog fileLogger = LogManager.GetLogger(GetType()); 
> When second thread starts and modifies the values, the subsequent logs from 
> other threads start using the same values. 
> Any suggestions? 
> When using web.config file for appender defintion, is this not thread safe? 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to