You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "MK Pandey (JIRA)" <ji...@apache.org> on 2010/04/26 06:44:34 UTC

[jira] Created: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

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
            Reporter: MK Pandey


 
Problem: We call log4net from our BizTalk 2006 orchestrations.  We noticed we were missing logging data. 
 
Doing a simple Nunit single threaded test, we would get all logged data. (repeatable)
In a Nunit multithreaded test, we would notice missed logged data. (repeatable)
Also, we also noticed  when BizTalk Host, when we lowered the amount of active threads down to 2 (the lowest we could go) 
 
So, We enabled debug tracing in log4net.  We also added various system.diag eventlogwrites around different parts of our code,  from where log4net was called, and also inside our appenders.
 
We noticed was saw an error in the debug tracing (using debugviewer)  log4net:ERROR [EventLogAppender] Attempted to append to closed appender named [EventLogAppender]. 
 
Also, by counting the number of eventlog entries we had from the various points, log4net itself was not calling the appenders each time it was called to log a message.
 
We seen this issue of log4net not calling the appenders, with a variety of different appenders, like the out of the box file and eventlog appenders and also our own msmq appender.
 
So log4net doesn't appear to be thread safe?  Any suggestions?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


AW: [jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by Dominik Psenner <dp...@gmail.com>.
Good morning.

As I understood your problem and the way log4net (and other log4*) works, a
logger is identified by its name, which is passed into the
LogManager.GetLogger(type) constructor delegator. Log4net then instantiates
exactly this one logger and gives you back the instance in future calls. If
you use it multiple times across different classes, you have of course the
same instance of the logger across these different classes.

So, to fix this problem, I would recommend using log4net as it was designed
and try one of these two things:

* do a LogManager.GetLogger(type) across the classes, hold there a instance
for this class in a static variable and pass it to the log helper. This
actually renders the log helper pretty useless, but it works.

* Implement the log helper as a wrapper and provide a constructor method
just like the LogManager.GetLogger(type) does. You may even provide a
interface that your helper implements. That way you would be able to switch
helper and implementation transparently and change logging facility in the
future.

* You can of course implement the second attempt so that it automatically
detects which class called the method and therefore looking up your class
for itself. Refer to c# reflections and examine the callstack in .NET. Note
that these operations cost a lot of performance.

Greetings,
D.

-----Ursprüngliche Nachricht-----
Von: MK Pandey (JIRA) [mailto:jira@apache.org] 
Gesendet: Montag, 26. April 2010 06:56
An: log4net-dev@logging.apache.org
Betreff: [jira] Updated: (LOG4NET-256) log4net With MDC is not exactly
threadsafe?


     [
https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.pl
ugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Attachment: bug detals mail.jpg

> 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
>         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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Comment: was deleted

(was: Hi All, 

So you mean, if we are using web.config file for appender defintion, we can not have it thread safe? 

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? )

> 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
>
> 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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Environment: Windows Server 2003, Windows XP  (was: Windows Server 2003)
    Description: 
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? 


  was:
 
Problem: We call log4net from our BizTalk 2006 orchestrations.  We noticed we were missing logging data. 
 
Doing a simple Nunit single threaded test, we would get all logged data. (repeatable)
In a Nunit multithreaded test, we would notice missed logged data. (repeatable)
Also, we also noticed  when BizTalk Host, when we lowered the amount of active threads down to 2 (the lowest we could go) 
 
So, We enabled debug tracing in log4net.  We also added various system.diag eventlogwrites around different parts of our code,  from where log4net was called, and also inside our appenders.
 
We noticed was saw an error in the debug tracing (using debugviewer)  log4net:ERROR [EventLogAppender] Attempted to append to closed appender named [EventLogAppender]. 
 
Also, by counting the number of eventlog entries we had from the various points, log4net itself was not calling the appenders each time it was called to log a message.
 
We seen this issue of log4net not calling the appenders, with a variety of different appenders, like the out of the box file and eventlog appenders and also our own msmq appender.
 
So log4net doesn't appear to be thread safe?  Any suggestions?


> 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
>
> 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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------


Hi All, 

So you mean, if we are using web.config file for appender defintion, we can not have it thread safe? 

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? 

> 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
>            Reporter: MK Pandey
>
>  
> Problem: We call log4net from our BizTalk 2006 orchestrations.  We noticed we were missing logging data. 
>  
> Doing a simple Nunit single threaded test, we would get all logged data. (repeatable)
> In a Nunit multithreaded test, we would notice missed logged data. (repeatable)
> Also, we also noticed  when BizTalk Host, when we lowered the amount of active threads down to 2 (the lowest we could go) 
>  
> So, We enabled debug tracing in log4net.  We also added various system.diag eventlogwrites around different parts of our code,  from where log4net was called, and also inside our appenders.
>  
> We noticed was saw an error in the debug tracing (using debugviewer)  log4net:ERROR [EventLogAppender] Attempted to append to closed appender named [EventLogAppender]. 
>  
> Also, by counting the number of eventlog entries we had from the various points, log4net itself was not calling the appenders each time it was called to log a message.
>  
> We seen this issue of log4net not calling the appenders, with a variety of different appenders, like the out of the box file and eventlog appenders and also our own msmq appender.
>  
> So log4net doesn't appear to be thread safe?  Any suggestions?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Attachment:     (was: Bug details - mail.jpg)

> 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
>
> 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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Attachment: bug detals mail.jpg

> 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
>         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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOG4NET-256) log4net With MDC is not exactly threadsafe?

Posted by "MK Pandey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4NET-256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MK Pandey updated LOG4NET-256:
------------------------------

    Attachment: Bug details - mail.jpg

> 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
>
> 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 is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.