我想在我的应用程序中有2个日志文件。第一个记录所有记录器的所有消息,除了特定详细记录器的DEBUG输出,我想进入第二个日志文件。
我仍然希望看到来自详细记录器的INFO - FATAL消息进入第一个日志文件。这可能吗?
我看到了向appender-refs here添加阈值元素的建议,但它似乎无法正常工作。
这是我到目前为止所做的:
<log4net>
<appender name="fileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log4net" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="'.'yyyyMMdd'.log'" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="fileAppender" />
</root>
<!-- Separate appender for the Verbose logger debug output -->
<appender name="verboseDebugAppender" type="log4net.Appender.RollingFileAppender">
<file value="verboselog" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="'.'yyyyMMdd'.log'" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="DEBUG" />
</filter>
</appender>
<logger name="VerboseLogger" additivity="false">
<level value="DEBUG" />
<!-- Doesn't work -->
<appender-ref ref="verboseDebugAppender">
<threshold value="ALL" />
</appender-ref>
<appender-ref ref="fileAppender">
<threshold value="ERROR" />
</appender-ref>
</logger>
</log4net>
答案 0 :(得分:0)
我看到一个问题:
删除这些行
<!-- Doesn't work -->
<appender-ref ref="verboseDebugAppender">
<threshold value="ALL" />
</appender-ref>
<appender-ref ref="fileAppender">
<threshold value="ERROR" />
</appender-ref>
并更改
<root>
<level value="ALL" />
<appender-ref ref="fileAppender" />
</root>
到
<root>
<appender-ref ref="verboseDebugAppender">
<threshold value="ALL" />
</appender-ref>
<appender-ref ref="fileAppender">
<threshold value="ERROR" />
</appender-ref>
</root>