[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4net-user
Subject:    Fwd: Log4net.ThreadContext.Properties Having stale data. How to resolve it?
From:       Ananth Tatachar <ananth.tatachar () gmail ! com>
Date:       2014-07-24 0:31:32
Message-ID: CAL8uD2vRWYua0QW2tGV1jJmvY5mAcAxWz7pkcmhXCJWqONYq4A () mail ! gmail ! com
[Download RAW message or body]

---------- 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
it?
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"] =
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.

[Attachment #3 (text/html)]

<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message \
----------<br>From: <b class="gmail_sendername">Ananth Tatachar</b> <span \
dir="ltr">&lt;<a href="mailto:ananth.tatachar@gmail.com">ananth.tatachar@gmail.com</a>&gt;</span><br>
                
Date: Wed, Jul 23, 2014 at 8:24 PM<br>Subject: Log4net.ThreadContext.Properties \
Having stale data. How to resolve it?<br>To: <a \
href="mailto:log4net-user@logging.apache.org">log4net-user@logging.apache.org</a><br><br><br>
 <div dir="ltr"><div>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.</div>

<div><br></div><div>My logging function looks like \
this:</div><div><br></div><div><br></div><div>      \
log4net.ThreadContext.properties[&quot;randomGeneratedData&quot;] = \
randomGeneratedData;</div><div>      private ILog myLog =  </div>

<div>                 LogManager.GetLogger(typeof(LogTest));</div><div>      using \
(log4net.NDC.Push(&quot;ndcTest1&quot;))</div><div>      {</div><div>            \
using (log4net.NDC.Push(&quot;ndcTest2&quot;))</div><div>                  {</div>

<div>                        myLog.Info(&quot;myLogTest&quot;);</div><div>            \
}</div><div>      }</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>Result \
of logging:</div><div><br></div> <div>
           NDC = &quot;ndcTest1 ndcTest2&quot; , randomGeneratedData = \
rad1</div><div>           NDC = &quot;ndcTest1 ndcTest2&quot; , randomGeneratedData = \
rad2</div><div>           NDC = &quot;&quot;, randomGeneratedData = rad2  </div>

<div><br></div><div>and so on ...</div><div><br></div><div><br></div><div>I tried to \
clear log4net.ThreadContext.Properties before filling it again , but it was of no \
use. Please help.  </div></div> </div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic