%property does not work with RollingFileAppender in log4net
I have been doing what it was suggested in Best way to dynamic开发者_如何学Cally set an appender file path to set the file name dynamically, using %property{}, but the file is created as "(nul).log" below is the code
log4net.GlobalContext.Properties["service"] = _servicename.ToString();
_flatFileLogger = LogManager.GetLogger("FlatFileLogger");
_flatFileLogger.Debug(logData.ToString());
I have declared in the XML file as
file type="log4net.Util.PatternString" value="C:\My_Log\%property{service}.log"
Help much appreciated.
Make sure you're setting the property before you initialize log4net.
Do not confuse loggers and appenders. Most people use one logger per class: This way your log messages can easily be put in relation to your classes.
Appenders on the other hand have nothing to do with the way your program is structured. In your configuration you can tell which loggers should use which appenders. This gives you great flexiblity, that you would not have you if you use "appenders" directly in code.
Do you have any other logger that write a statement before the one you posted? If so then I would assume that the file appender is already initialized (with null in the name).
精彩评论