我已经成功封锁了我自己的登录自己的General&错误日志文件。
我已经将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>
答案 0 :(得分:8)
从根目录中删除NHibernate appender,并将additivity="false"
添加到你的nhibernate 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" />
</root>
<logger name="NHibernate.SQL" additivity="false">