I’m brand new to log4net, and I’m trying to maintain some legacy code that uses it. I’ve noticed that having two static classes that tell log4net to log to different locations are tripping over each other.
The classes each have a static constructor that looks like this
static Logger() {
_Logger = new X.LoggingService.AppLogger(
X.UtilityServer.Configuration.ConfigInfo.LoggerConfigFile);
}
except with different config values; both of these static classes are initializing the same AppLogger helper class. The second class to initialize is overwriting the initialization of the first. I think I’ve tracked the problem down to here:
private ILog Log {
get {
if (!_ConfiguratorSet) {
_ConfiguratorSet = true;
XmlConfigurator.Configure(new FileInfo(_ConfigFile)); //<--- STATIC
}
return _log;
}
}
Since I absolutely do not have to support thread safety, should I just get remove the if statement? Would calling XmlConfigurator.Configure every time I need to log something be prohibitively expensive? Is there a better way? This code was written using log4net version 1.2.10
Ideally, what shall be happening is:
The code
is really confusing and wrong. You should only return a log there, so no ifs at all. It is a violation of single responsibility principle and possibly the reason of the bug you see.