Tuesday 23 October 2007

log4net troubles one among several

After having successfully used log4net to implement a new proxy client ( used nUnit tests to test) I now find myself in some difficulty. Because to test the proxy even further I want to run another program, which uses my Dll to talk to the server.

My first problem is of course that programs are never as loosely coupled as one could wish, and therefore I had to remove some hard coded references from the new test program.

Now that the tests actually run my code, I have a problem with configuring the log4net framework.

First thing is to study the application configuration file a bit, Visual Studio allows you to create a file called app.config by right clicking on the solution title in the solution explorer (the thing usually on the right). This file will then be copied to the bin dir, with the proper name, when the solution is compiled (link).

Solution:
The thing that should be remember is to add the following line somewhere its sure to be called before the log is used:

log4net.Config.XmlConfigurator.Configure()

At least if you are configuring the log4net in the app.config file.

No comments: