Koevoeter wrote:
Hi,
My application uses NHibernate and log4net for my specific application logging while NHibernate also uses log4net.
My question: How can I configure log4net and NHibernate to use seperate files for NHibernate logging and application logging?
I've seen some posts but they always suggest to set levelrange filters to do this. That way eg errors would be NHibernate and info's would be application. Ofcourse this can never be the idea of logging. I'm looking for an NHibernate setting that tells NHibernate which appender to use.
If not possible, can someone tell me how to disable logging in NHibernate?
Thanks
Koen
To disable NHibernate Logging altogether, explicitly set it's log level to none.
Code:
<logger name="NHibernate">
<level value="NONE"/>
</logger>
To have nHibernate log to a different file give it it's own appender by using the appender-ref element.
Code:
<logger name="NHibernate">
<level value="DEBUG"/>
<appender-ref ref="nHibernateAppender"/>
</logger>
Of course you need to set up a separate appender for this to work
Code:
<appender name="mainApp" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="applog.txt" />
<param name="AppendToFile" value="false" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="nHibernateAppender" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="nhibernatelog.txt" />
<param name="AppendToFile" value="false" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
And that should do it for you.[/code]