I am using log4net in a C# project, in the production environment, I want to disable all the logging, but when some fatal error occures it should log all the previous 512 messages in to a file.I have successfully configured this, and it is working fine. It logs the messages in to a file when some fatal error occures.
但是,当我从Visual Studio运行它时,我可以看到所有的日志消息都被写入了Output窗口,无论它是否是Fatal。(当我从Windows资源管理器运行时,我看不到这些消息-我的应用程序是WinForm exe,没有控制台窗口可以查看输出)
有什么方法可以禁用此日志记录吗?我只需要在文件中保存日志,当发生致命错误时也是如此。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net debug="false">
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender" >
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="FATAL"/>
</evaluator>
<appender-ref ref="RollingFileAppender" />
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="BufferingForwardingAppender" />
</root>
</log4net>
</configuration>
这就是我在Windows窗体的静态初始值设定项中配置它的方式。
static Window1()
{
Stream vStream = typeof(Window1).Assembly.GetManifestResourceStream("TestLogNet.log4net.config");
XmlConfigurator.Configure(vStream);
BasicConfigurator.Configure();
}
我在WinForm的构造函数中初始化了记录器对象
logger = LogManager.GetLogger(typeof(Window1));
[language - C#, .NET Framework - 3.5, Visual Studio 2008, log4net 1.2.10, project type - WinForms]