I want to log to multiple files (2 different files only) but leave the logger name the same as the class name like is typically done:
private static readonly log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, isReadOnly);
I want to keep the class name so I can output it to the logger.
The problem is, I need to dynamically switch between appenders based on the wcf method being called (this is a wcf service). I tried various log4net config settings, including this solution:
Configure Log4net to write to multiple files
But many solutions have pre-defined logger names which I don't want. I also don't want to hard code all my different class names in the log4net config and reference those specific loggers (maintenance nightmare).
What I'm looking for is something like this:
public static ILog GetLogger(Type classType, bool shouldLogToFile2)
{
if (shouldLogToFile2)
{
return LogManager.GetLogger(classType, file2Appender); // log to file2.log (this statement doesn't compile)
}
else
{
return LogManager.GetLogger(classType, file1Appender); // log to file1.log (this statement doesn't compile)
}
}
And call it like so:
ILog log = GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, true);
log.Info("This should log to file2.log");