Have you looked at MessageObjectExpanderAppender?

http://tinyurl.com/3dnnf3
http://svn.apache.org/viewvc/logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender/MessageObjectExpanderAppender.cs?view=markup

Its a forwarding appender that extracts all the public properties from the 
MessageObject and places their values in the LoggingEvent's Properties so the 
appender that actually does the logging can access them.

----- Original Message ----
From: Matthew Braid <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, February 1, 2007 6:03:30 PM
Subject: Retrieving MessageObject property values for logging...

Hi

Does a mechanism exist through which I can access the contents of the 
MessageObject (within the LoggingEvent) via the layout patterns?

For example, in my project I'm logging classes MyLogEvent to log4net rather 
than strings. I intended reusing existing appenders (such as the 
AdoNetAppender) to log these rather than write my own but can't see a way of 
accessing my specific object's properties.

Looking at the source (v1.2.10) I couldn't see anything within the 
PatternLayout that would cover this scenario, so I've added a new 
log4net.Layout.Pattern.MessageObjectPatternConverter (modelled on the 
PropertyPatternConverter) and wired it into the PatterLayout invoked as 
%object{<object property>}.

Does anyone have any views on the desirability or practicality of such a 
feature? If there's interest I'm more that happy to contribute the code and 
unit tests, otherwise I'll investigate other routes.

Thanks
Matt.





Reply via email to