Developers, Technology Evangelists, Bros.

Logging Additional Properties in Log4net

Log4net is a great logging framework that I find myself using whenever I need to setup logging in my projects.  Normally I setup some basic logging to text files and that is sufficient for most projects.  Recently I had a situation arise where I needed to add some additional target debug logging to a project to help troubleshoot an issue.  I chose to setup a new AdoNetAppender for this task because I had several sources that I needed to log, I could more easily manipulate and browse my data, and I did not need to disturb my current error logging.

Setting up the AdoNetAppender was  easy – I just added the following lines to my web.config.  Be sure to note the special pattern layouts we use in the configuration of log4net so that it can access these extra properties you set.

You will notice that if you try this user, application, and ndc are not default properties out of the box.  These are properties that we need to set in code.  This is a simple task.

That’s all it takes and you’re logging each property in its own column in your database!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.