OMG!! Add data 1 time to record with ALL logs - Logger.SetContextItem()

Topics: Exception Handling Application Block, General discussion, Logging Application Block
Nov 20, 2007 at 1:03 AM
I just found SetContextItem()... Now I get to go back and re-write all the code I created to do this myself. I wish I found this a week ago...

If your unaware (like me) EntLib has the ability to set 'extended properties' key/value once which will then be written to all log entries (trace / logging / exceptions) via the Logger.SetContextItem() method. You can add key/value pairs at any time which will then be written to ALL subsequent Logs thereafter. This is great for tracking something like a SessionID across all log entries or creating a correlation Entry with something more meaningful to you than a Guid.

PLEASE ADD THIS TO THE DOCUMENTATION - I recommend referencing the capability here:

Please let me know if this was useful to you... it will re-assure me that I am (or am not) a complete idiot :?

p.s. I found this by accident when browsing the object tree