在运行时改变log4net的转换模式或布局 [英] Change log4net conversion pattern or layout at runtime
本文介绍了在运行时改变log4net的转换模式或布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用LOGINFO()方法登录到一个滚动的平面文件,但我需要更改转换图案或图案布局(无论你怎么称呼它),在某些情况下调用时,它是暂时的。这可能吗?
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?
推荐答案
的确是这样,比如像这样的:
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");
}
这篇关于在运行时改变log4net的转换模式或布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文