我已经成功地封锁了我自己的登录到它自己的常规和错误日志文件。
我已将 NHibernate 添加到组合中,因为我想记录它生成的 sql 语句以帮助调试 - 但到它自己的文件中。
使用下面的当前配置,NH 输出最终出现在我的常规日志文件 (CommunicationsAppender) 以及它自己的文件中(它是重复的)。如何将输出排除在 CommunicationsAppender 之外?
<log4net>
<appender name="NHibernateAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\logs\NHibernate.log"/>
<appendToFile value="true"/>
<maximumFileSize value="1000KB"/>
<maxSizeRollBackups value="10"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger %level - %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="NHibernate.SQL" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="CommunicationsAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\Communications Service.log"/>
<appendToFile value="true"/>
<maximumFileSize value="10000KB"/>
<maxSizeRollBackups value="10"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger - %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="WARN" />
</filter>
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="CommunicationsLogger" />
<acceptOnMatch value="true" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<appender name="CommunicationsErrorAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Logs\Communications Service Errors.log"/>
<appendToFile value="true"/>
<maximumFileSize value="10000KB"/>
<maxSizeRollBackups value="10"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger - %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="CommunicationsLogger" />
<acceptOnMatch value="true" />
</filter>
</appender>
<root>
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
<priority value="ALL"/>
<!--<appender-ref ref="LogToFile"/>-->
<appender-ref ref="CommunicationsAppender" />
<appender-ref ref="CommunicationsErrorAppender" />
<appender-ref ref="NHibernateAppender" />
</root>
<logger name="NHibernate.SQL">
<level value="DEBUG"/>
<appender-ref ref="NHibernateAppender"/>
</logger>
<logger name="NHibernate">
<level value="OFF" />
</logger>
</log4net>