Jonathan Beerhalter Jonathan Beerhalter - 9 months ago 137
C# Question

How do I create an asynchronous wrapper for log4net?

By default, log4net is a synchronous logging mechanism, and I was wondering if there was a way to have asynchronous logging with log4net?

Answer Source

If you go to the log4net website, you can find some examples, at least one of which is an asynchronous Appender.

http://logging.apache.org/log4net/release/example-apps.html

Note that I have not used any of these examples, so I cannot vouch for them one way or the other.

Here is a link to the actual asynchronous appender from the log4net Examples area in their code repository:

http://svn.apache.org/viewvc/logging/log4net/trunk/examples/net/2.0/Appenders/SampleAppendersApp/cs/src/Appender/AsyncAppender.cs?view=markup

I looked at it briefly, and it apparently acts as a wrapper around one or more "conventional" Appenders. On each logging request (containing one or more LoggingEvent objects), a ThreadPool thread is used to forward the LoggingEvents to the list of wrapped Appenders.