---------- Forwarded message ----------
From: Ananth Tatachar <[email protected]>
Date: Wed, Jul 23, 2014 at 8:24 PM
Subject: Log4net.ThreadContext.Properties Having stale data. How to resolve
it?
To: [email protected]
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"] =
randomGeneratedData;
private ILog myLog =
LogManager.GetLogger(typeof(LogTest));
using (log4net.NDC.Push("ndcTest1"))
{
using (log4net.NDC.Push("ndcTest2"))
{
myLog.Info("myLogTest");
}
}
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.