Commonly, we use log4net for unit testing in .net, because of it's standard log4j-like style. But sometimes it seems that log4net not stress-effective, so remove dependency on it is right decision. In .net there isn't any widely adopted library for this like Jakarta's Commons Logging, so as we use Spring.net for DI, we use it's Common Logging library, which let us decoupling from log4net.
One thing that we not understand immediately is that how to configure logmanager in unit tests.
In log4net (as well as log4j) you can simply use BasicConfigurator:
1 BasicConfigurator.Configure(); 2 3 LogManager. 4 GetLogger(typeof(C1DocC1DirectDAOTest)). 5 Debug("LOGGING SETUP");
But using it with Common Logging has no effect. Right way is setting adapter for LogManager.
1 NameValueCollection properties = new NameValueCollection(); 2 properties["level"] = "Debug"; 3 4 Common.Logging.LogManager.Adapter = 5 new ConsoleOutLoggerFactoryAdapter(properties); 6 7 Common.Logging.LogManager.GetLogger(typeof (C1DocC1DirectDAOTest)). 8 Debug("SPRING LOGGING SETUP");
Other implementations can be found in doc.
