Wednesday, September 19, 2007

Using log4net with NUnit

If you are like myself, you want to watch the log4net debug output while running my NUnittests. How to do it?

One interesting approach is described here.

A lighter alternative to consider, that also works nicely with NUnit GUI: make your test assembly to configure and load log4net.

1) Create an Application Configuration file for the test class library.
2) Add there log4net section, configure the logger
3) Add log4net configuration attribute to your AssemblyInfo.cs:

// Load log4net logger
[assembly: log4net.Config.XmlConfigurator(

Note that I renamed the auto-generated App.config to "MyTests.conf", and set it up to copy to output directory "If newer". It is a matter of the taste: you could leave App.config, and refer to it as ConfigFile="MyTestAssemblyFullName.dll.config"

PS. Is it time to move on to MBUnit?

Labels: ,

AddThis Social Bookmark Button


At 9/25/2007 04:29:00 PM , Anonymous Sameer Alibhai said...

Have you considered Cruise Control? It allows you to automate running NUnit on each build, and will give you the output in a very cool web-dashboard.. I am in the process of implementing it here and we are MOST impressed.

At 9/25/2007 10:32:00 PM , Blogger Dmitri Zimin(e) said...

We absolutely do use Cruise Control on all production projects. In fact all production code, which is a whole lot, is built nightly and smoke tested.

However Cruise Control doesn't matter: it is not about a cool tool but right practice. For Continuous Integration you _must_ have Cruise Control. Do you need continuous integration? Good question to ask. The answer is, as usual, it depends. With 3 people on the project it might be overkill. With 10 it is the matter of survival.

At 2/16/2009 02:21:00 PM , Blogger GaussC said...

The solution didn't work in my setting. I don't know the root cause of this problem and I don't want to waste time to search for it, so I prepared alternative solution for those who have similar problems to mine. Additionally I show how to test log4net configuration (yes! this should be tested too ;-)


Post a Comment

<< Home