Centralised Application logging via Log4Net

Logging is now an essential part of any serious application. It is crucial to get unhandled exceptions from production and development environments logged. This removes the necessity for users to provide error messages, and allows the developers to have access to full stack traces which often reveals sources of defects immediately.

Log4Net offers many different ways of logging. There are many different appenders, but it is possible to get centralised logging from different clients and applications.

Our requirements are that logging messages should have guaranteed delivery, and not impact application performance. We need to receive messages on a single machine, and be able to view those effectively.

Therefore, we cannot use the UdpAppender as these message would not be guaranteed to arrive. The AdoNetAppender works synchronously, and we found it had a material impact on our app’s performance.

The solution we settled on is a bit more convoluted than I would have liked, but has been running for months now, and works really well.

We use the RemoteSysLogAppender to forward messages to a server that is running Kiwi Syslog daemon which is a fairly inexpensive product.

The configuration for this appender is reasonably simple:

<appender name="RemoteSyslogAppender" type="log4net.Appender.RemoteSyslogAppender">
      <layout type="log4net.Layout.PatternLayout" value="%date{dd/MM/yyyy hh:mm:ss,fff} | %thread | %level | %logger | %username | %P{log4net:HostName} | dev | %message | %exception | "/>
      <remoteAddress value="LOGSERVER" />
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ALL" />
      </filter>
    </appender>

We then configure Kiwi to forward it’s messages to a database.

Finally we use another Log4Net Dashboard, another inexpensive product to view the messages that have been received. Kiwi is configured to match the schema Log4Net Dashboard expects.

Our NAnt build scripts deal with the different configurations for development, QA, and production logging.

I am sure that there are alternative ways to achieve this same goal along, but this was a low cost and easy way to achieve robust logging so we have confidence that we can view the health of our applications.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
This entry was posted in log4net, logging. Bookmark the permalink.

One Response to Centralised Application logging via Log4Net

  1. Stu says:

    Thanks Simon, that was really useful. I’d seen something very similar in a previous workplace but couldn’t remember exactly how to differenciate between production and dev.

    Good blog, I’ll look forward to reading more in the future.

Comments are closed.