Change log4net conversion pattern or layout at runtime

余生颓废 提交于 2019-12-22 04:37:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!