I don't understand your concern. Log4net doesn't ship with an Appender that
does what you want...how else are you going to achieve the desired
functionality if you don't extend one of the built-in classes? The Append
method was marked abstract for this very reason. The
MessageObjectExpanderAppender is effectively 10 lines of code and has been more
less unchanged for 2+ years.
The appenders in the example directory are working examples of how to
extend/tweak log4net if it doesn't do exactly what you want. They aren't
necessarily the fastest or only implementation of something. I think NLog's
async appender/target is faster than the AsyncAppender. I don't recall how much
faster/slower it is. There's certainly nothing stopping log4net's AsyncAppender
from being just as fast. Its just that no one has bothered to benchmark the
code and come up with faster implementation.
An simple improvement to MessageObjectExpanderAppender might be to cache the
PropertyInfo objects returned from messageType so the call to GetProperties
only happens once per Type:
foreach(PropertyInfo propertyInfo in TypeHelper.GetProperties(messageType))
{
// snip
}
Another improvement may be to allow the user to specify which objects have
their properties extracted and what properties get extracted:
<extractType value="Company.Person, Company">
<property value="FirstName" />
<property value="LastName" />
</extractType>
----- Original Message ----
From: Matthew Braid <[EMAIL PROTECTED]>
To: Log4NET Dev <[email protected]>
Sent: Friday, February 2, 2007 7:31:20 AM
Subject: Re: Retrieving MessageObject property values for logging...
Thank I will, at a glance it looks like it'll give me what I need.
However, what's the relationship between the Appenders in the examples and
the core log4net Appenders? If I start to use this and others such as the
AsyncAppender how do they figure in the overall product.
Thanks for the assistance.
----- Original Message -----
From: "Ron Grabowski" <[EMAIL PROTECTED]>
To: "Log4NET Dev" <[email protected]>
Sent: Friday, February 02, 2007 4:30 AM
Subject: Re: Retrieving MessageObject property values for logging...
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.