logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ananth Tatachar <ananth.tatac...@gmail.com>
Subject Fwd: Log4net.ThreadContext.Properties Having stale data. How to resolve it?
Date Thu, 24 Jul 2014 00:30:09 GMT
---------- Forwarded message ----------
From: Ananth Tatachar <ananth.tatachar@gmail.com>
Date: Wed, Jul 23, 2014 at 8:24 PM
Subject: Log4net.ThreadContext.Properties Having stale data. How to resolve
To: log4net-user@logging.apache.org

I am using a RollingFileAppender , and my own custom layout. My application
is multithreaded. Each thread will generate unique random data and is
supposed to log it using log4net framework. However if I create multiple
threads in quick succession I notice stale data in my logs , this goes away
if each thread sleeps for 50 ms before logging. I am not able to figure out
a solution to this issue or find its cause please do help me.

My logging function looks like this:

    log4net.ThreadContext.properties["randomGeneratedData"] =
    private ILog myLog =
    using (log4net.NDC.Push("ndcTest1"))
        using (log4net.NDC.Push("ndcTest2"))

Result of logging:

       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad1
       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad2
       NDC = "", randomGeneratedData = rad2

and so on ...

I tried to clear log4net.ThreadContext.Properties before filling it again ,
but it was of no use. Please help.

View raw message