How to log only the queries that are executed

It is possible to have log4net log only the queries that are are executed by NHibernate.  In this sample, all queries generated by NHibernate will be stored in the file log.txt. 

In your app.config, you will need to add the following sections to your app.config:

<configSections> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 
</configSections>
 <log4net>
   <appender name="rollingFile"
type="log4net.Appender.RollingFileAppender,log4net" >
     <param name="File" value="log.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>
   </appender>

   <logger name="NHibernate.SQL">
     <level value="ALL" />
     <appender-ref ref="rollingFile" />
   </logger>

 </log4net>

Enjoy!

 

Print | posted on Thursday, April 03, 2008 3:09 PM

Comments on this post

# re: How to log only the queries that are executed

Requesting Gravatar...
Great tip!
I'm already using Log4net as logger of my application.
Is there a wait to separe this entries in a different file ?
Thks
Left by makka on Apr 07, 2008 5:20 AM

Your comment:

 (will show your gravatar)
 
Please add 7 and 7 and type the answer here: