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