views:

21

answers:

1

So I'm using log4net to write log output to the trace. Show sql is specified in the configuration file. I seem to have to set the log output level to DEBUG to get the SQL output, but DEBUG also produces pages and pages of other guff I have to scroll past.

Can I get the SQL without the guff?

Thanks

David

+3  A: 

You can add a logger for NHibernate.SQL in the log4net config block, like so:

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

With the appender-config

<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date - %message%newline"/>
  </layout>
</appender>

(replace this with whatever you prefer, like rollingFileAppender)

Another option is using a tool like NHibernate Profiler.

tijmenvdk
I already had an appender, so I just added the logger element and set its appender-ref ref attribute to the name of the appender.
David
Also, show_sql is independent from log4net SQL logging.
Diego Mijelshon