如何禁用控制台的 log4net 状态消息? [英] How do I disable log4net status messages to the console?
问题描述
我在我的 .NET 3.5 控制台应用程序中使用 log4net,并希望在控制台标准输出和 RollingFileAppender 中都能看到我生成的日志消息.文件输出就像一个魅力,但是当我执行时,我看到一串状态消息流向控制台标准.我想跳过所有状态信息,只看到我以编程方式生成到日志文件的相同消息.
I am using log4net in my .NET 3.5 console application and would like the log messages I generate to be seen in both the console standard out and the RollingFileAppender. The file output is working like a charm, but I am seeing a stream of status messages flowing to the console standard out when I execute. I would like to skip all the status information and only see the same messages I am programmatically generating to the log file.
这是我运行应用程序后看到的示例:
Here is an example of what I see after I run my app:
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [DEBUG].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="DEBUG",value=30000].
log4net: XmlHierarchyConfigurator: Loading Appender [Console] type: [log4net.Appender.ConsoleAppender]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
它会一直持续下去,直到它描述了记录器对象的整个实例化.
and it keeps on going until it describes the whole instantiation of the logger object.
如何关闭此功能?我可以吗?我已经尝试了各种配置文件设置,但没有什么能让这些消失!呜呜呜……
How do I turn this off? Can I? I've tried all sorts of config file settings, but nothing makes these go away! Grrr...
推荐答案
set debug = false
set debug = false
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="your file name" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>
这篇关于如何禁用控制台的 log4net 状态消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!