views:

377

answers:

3

I have this in my web.config file (edited to reflect some changes):

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>

  <log4net debug="true">
    <appender name="DebugAppender" type="log4net.Appender.AspNetTraceAppender">
      <layout type="log4net.Layout.PatternLayout, log4net">
        <param name="ConversionPattern" value="%d %p %m%n" />
      </layout>
    </appender>
    <appender name="DataLog" type="log4net.Appender.RollingFileAppender">
      <file value="c:\temp\nhlog.txt" />
      <appendToFile value="true" />
      <maximumFileSize value="100MB" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
      </layout>
    </appender>
    <root>
      <priority value="DEBUG" />
      <appender-ref ref="DebugAppender" />
    </root>
    <logger name="NHibernate" additivity="false">
      <level value="INFO"/>
      <appender-ref ref="DebugAppender"/>
    </logger>
  </log4net>

I'm calling log4net.Config.XmlConfigurator.Configure() from Application_Start().

I have [assembly: log4net.Config.XmlConfigurator(Watch = true)] in the AssemblyInfo.cs file in my web project.

Why do I get no NHibernate debugging messages in my output window? (I trying to get ALL of the messages that NHibernate spits out.) If I use the RollingFileAppender it works fine. I've tried the DebugAppender, TraceAppender, OutputDebugStringAppender, and AspNetTraceAppender and none of them output stuff to the output window.

+1  A: 

You could try to associate the specific NHibernate logger with a log4net appender.

If you want to log all the generated sql, try adding this to your log4net config section:

<logger name="NHibernate.SQL" additivity="false">
  <level value="DEBUG" />
  <appender-ref ref="ConsoleAppender" />
</logger>

If, for some reason, you only wanted to log Select statements and diagnostic info, you could use NHibernate.Loader.Loader, like this:

<logger name="NHibernate.Loader.Loader" additivity="false">
  <level value="INFO" />
  <appender-ref ref="ConsoleAppender" />
</logger>
joshua.ewer
+2  A: 

Try using a different appender.

ConsoleAppenders probably don't work for web applications. Use something like a FileAppender.

See this for examples on configuraiton.

quip
+2  A: 

Similar to quip's answer, ConsoleAppender is not the right appender to use in a web application. An OutputDebugStringAppender will give you messages in your debug window. You may also want to look into AspNetTraceAppender.

John Rayner