Asynchronous Log4Net Appenders
I have spent the majority of my time over the last week performance profiling an enterprise application using ANTS Performance Profile. The results showed that we were having huge delays (over a second) on Log4Net when under load, which I thought was strange as it’s such a tried and tested logging framework. After some digging through their source code it’s evident that requests are processed on the calling thread, bad news for this situation! We use an AdoNetAppender so the slowdown was probably due to database contention because it’s a multi threaded architecture and the large number of requests that were being processed. I didn’t expect the loggers to use blocking calls however that’s just the way things are. Due to this I have come up with a couple of Asynchronous wrappers which run a background thread to call the base Appender and queue up the log requests in a RingBuffer which has a size limit to avoid excessive memory usage. The full production ready source code including unit tests is available on GitHub here.