Tuesday, 28 April 2009

Log4Net inside code run with MSTest unit testing

This was confusing me for a while so chances are it was also confusing someone else out there.

I could not get logging using log4net to output to the configured logger inside my unit tests
i tried
[assembly: log4net.Config. XmlConfigurator()]
in the unittest projects assembalyinfo but still log4net would not pick up the config

i found that the answer is to place an assembly initialise inside the unit test project, only one mind in the whole project. In fact if you do add 2 its an error

[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
log4net.Config.XmlConfigurator.Configure();
}

No comments:

Post a Comment