I have a wrapper class for log4net to log across multiple classes and assemblies within a group of dll-libraries. (This may be poor design, but.. don't ask) The code basically looks like this:
public static class Logger
{
private static ILog log;
static Logger()
{
log = LogManager.GetLogger("abcd");
XmlConfigurator.Configure(new FileInfo("LoggerConfig.log4net"));
log.Info("=== NEW SESSION ===");
}
public static void Log(string message)
{
log.Debug(message);
}
}
Now.. if the static constructor was the static main routine of a simple executable, this works perfectly fine (I quickly made a console app to test it). But here it does not. Since I deal with standalone assemblies, not executables, the only way I can easily test the logger is through MSTest. This may be a cause for this problem. I am not 100% sure if it maybe simply can't find the config file. It is copied at compilation and lies in the same folder as the assembly containing the logger class, so i think that should work.
bleh.. stuck since three hours. :T any suggestions?
My psychic debugger says that your LoggerConfig.log4net is not in the right directory. It is not deployed to your test directory and not found when running the test. That is why there is no log output. Deploy the file in the test directory and you will have you logging output.
EDIT: More precisely, you need to add it as a deployment file under Test->Edit Test Settings->>Deployment (as described here: How can I get "Copy to Output Directory" to work with Unit Tests? )