问题
I'm using the LogInfo() method to log to a rolling flat file, but I need to change the conversion pattern or pattern layout (whatever you want to call it) temporarily when calling it in a certain circumstance. Is this possible?
回答1:
Yes it is, for instance like this:
var appenders = log4net.LogManager.GetRepository().GetAppenders();
foreach (var rollingFileAppender in appenders.OfType<log4net.Appender.RollingFileAppender>())
{
rollingFileAppender.Layout = new log4net.Layout.PatternLayout("- %message%newline");
}
来源:https://stackoverflow.com/questions/3016108/change-log4net-conversion-pattern-or-layout-at-runtime