English 中文(简体)
Can t get log4net to output anything when using NHibernate
原标题:

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:	emp
hlog.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.

最佳回答

Try using a different appender.

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

See this for examples on configuraiton.

问题回答

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.

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>




相关问题
Log4Net and extra fields

Is it possible to insert extra fields into the database and use them in log4net? I have a UserId I would like to have in an extra field in the log-table. I have added the field in the log4net.config:...

log4net with .NET 4.0

I ve thrown together some code to tinker with the new .Net 4.0/VS 2010 pieces, but I can t seem to find a build of my logging framework of choice (log4net) for 4.0, and I m getting reference errors ...

Best logging approach for composite app?

I am creating a Composite WPF (Prism) app with several different projects (Shell, modules, and so on). I am getting ready to implement logging, using Log4Net. It seems there are two ways to set up the ...

log4net log files disappear when service restarted

We are using log4net to create our logfiles from Windows services, and we are using the RollingFileAppender rolling based on date. The version of log4net we are using is 1.2.9. Now for the issue. ...

How do I use a date pattern in a header/footer?

Here s my appender configuration from my app.config. This just prints out the literal string instead of translating it to the date (i.e., it literally prints "[START: %date{MM/dd/yy HH:mm} ]"). <...

热门标签