I have set the ThreadContext.Properties and need to update its value during the life-cycle of my code. In the past I have used log4j MDC and had to:
MDC.remove(TRACKING);
and then add another value by:
MDC.put(TRACKING, trackingIdStr);
Now that I am using Log4Net, our app uses Properties:
log4net.ThreadContext.Properties[“TrackingId”] = tracker;
Question: How do I remove the previous value and add a new value? Is it as easy as just:
log4net.ThreadContext.Properties[“TrackingId”] = tracker2;
Yes, it is that easy. You can reassign as you have shown in your question or you can remove the value altogether when you are finished with it.
If you want your context properties to be in effect for a specific section of code (via using) then you can try ThreadContext.Stacks: