You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Zimney, Christopher M." <ch...@wamu.net> on 2005/08/24 23:17:41 UTC

Enumerating Context properties.

Friends,

When using 1.2.8, 

I created a custom Layout that enumerated the entries of the
MappedContext exposed by a LoggingEvent:

// Append the MDC values if any exist
if(loggingEvent.MappedContext != null &&
loggingEvent.MappedContext.Count > 0)
{
    foreach(DictionaryEntry entry in loggingEvent.MappedContext)
    {
        // xTxtWriter instantiated earlier as an XmlTestWriter
        xTxtWriter.WriteStartElement(entry.Key.ToString());
        xTxtWriter.WriteString(entry.Value.ToString());
        xTxtWriter.WriteEndElement();
    }
}

The result is something like this:

<Context>
    <Entry1>Value1</Entry1>
    <Entry2>Value2</Entry2>
</Context>


In 1.2.9, the mapping is no longer exposed and I'm unsure how to
enumerate the entries of any of the new Context objects
(LogicalThreadContext, etc.)

Any ideas?


_____________
Chris Zimney
WaMu Online
206-461-4713