Hopefully, this will be threaded properly - I couldn't figure out how to
retrieve old messages from the list server.

I found this thread from MARC, and it got me interested because I was
looking for information on how to utilize NDC.  For the life of me, I
couldn't think of what NDC was for and how to use it.

Anyhow, how about you do this for an interim solution for the NDC
popping issue when an exception is thrown:
=====
 try
 {
  foreach (int oddNumber in oddNumbers)
  {
   using(NDC.Push("oddNumber: " + oddNumber))
   {
        log4net.ThreadContext.Properties["NDC2"] = NDC.ToString();
    foreach (int evenNumber in evenNumbers)
    {
     using(NDC.Push("evenNumber: " + evenNumber))
     {
        log4net.ThreadContext.Properties["NDC2"] = NDC.ToString();
      if (oddNumber == 7)
      {
       throw new ApplicationException("Oh no!");
      }
      log.DebugFormat("Sum: {0}", 
       oddNumber + evenNumber);
     }
    }
   }
  }
 }
 catch (Exception ex)
 {
  log.Fatal(
   "Unhandled exception. Cause: " + ex.Message, ex);
 }
=====
So, the idea is to put a copy of the stack into another Name/Value pair
every time you push.  I know it's clunky but it's better than forgetting
to pop by replacing using statements with a try..catch?  I thought about
using

log4net.ThreadContext.Properties["NDC2"] = NDC.CloneStack();

but, it seems to make a shallow copy.

The better solution would be for the log4net to make a snapshot of the
stack every time it's pushed, so that in our situation, even when
everything is popped, there remains the last pushed snapshot, if you
will.

NDC.LastPushState (for lack of better term)

Will always return the last pushed snapshot(instance of
ThreadContextStack) of the stack.

Jiho Han
Senior Software Engineer
Infinity Info Systems
The Sales Technology Experts
Tel: 212.563.4400 x216
Fax: 212.760.0540
[EMAIL PROTECTED]
www.infinityinfo.com

Reply via email to