我正在记录nHibernate生成的所有SQL,因为我们有一个奇怪的问题。仅此一项就会产生巨大的日志,所以我试图通过尝试仅记录包含特定ID的行来缩短它们。看起来好像一切都将通过。这有什么看起来很奇怪吗?
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="nHibernate.txt" />
<param name="AppendToFile" value="true" />
<param name="DatePattern" value="yyyy.MM.dd" />
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d %p %m%n" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="5764" />
<acceptOnMatch value="true" />
</filter>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</logger>
答案 0 :(得分:22)
事实证明你需要添加以下代码:
<filter type="log4net.Filter.DenyAllFilter" />
完整的区块如下所示:
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="nHibernate.txt" />
<param name="AppendToFile" value="true" />
<param name="DatePattern" value="yyyy.MM.dd" />
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d %p %m%n" />
</layout>
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="5764" />
<acceptOnMatch value="true" />
</filter>
<!-- need this here! -->
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</logger>