Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get real sql from NHibernate with Log4Net
    text
    copied!<p>I decided to learn how to use an ORM to avoid learning some SQL (mistake -- only approach would be to go no-SQL).</p> <p>I have been able to get the Nhibernate "SQL" using Log4Net, using the instructions that are duplicated in quite a few blogs. I get "SQL" like this:</p> <pre><code>NHibernate.Loader.Loader: 2011-11-11 15:03:14,348 [9] INFO NHibernate.Loader.Loader [(null)] - SELECT this_.RegionID as RegionID9_0_, this_.RegionDescription as RegionDe2_9_0_ FROM Region this_ </code></pre> <p>Now correct me if I am wrong but that is not SQL, and I can't understand why all of these blogs talk like it is.</p> <p>The strange thing is that earlier when I was messing around with log4net, I am sure that I was able to get ordinary SQL logged to a logfile. When I basically did getall() of an entity (read a whole table), all of the individual queries were listed there with the id in the query -one for each row(entity). I definitely didn't imagine this. Can anyone tell me how this is done with log4net? Here is my config right now:</p> <pre><code>&lt;log4net&gt; &lt;appender name="DebugSQL" type="log4net.Appender.TraceAppender"&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net"&gt; &lt;param name="File" value="log.txt"/&gt; &lt;param name="AppendToFile" value="true"/&gt; &lt;param name="DatePattern" value="yyyy.MM.dd"/&gt; &lt;layout type="log4net.Layout.PatternLayout,log4net"&gt; &lt;conversionpattern value="%d %p %m%n"&gt; &lt;/conversionpattern&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;logger name="NHibernate.Loader.Loader" additivity="false"&gt; &lt;level value="All"/&gt; &lt;appender-ref ref="DebugSQL" /&gt; &lt;/logger&gt; </code></pre> <p></p> <p>Edit: I now know that it was sql, and I couldn't reproduce the emitted sql that I had seen earlier because lazyloading was on before:</p> <pre><code>NHibernate.SQL: SELECT region_.RegionDescription as RegionDe2_9_ FROM Region region_ WHERE region_.RegionID=@p0;@p0 = 1 [Type: Int32 (0)] NHibernate.SQL: SELECT region_.RegionDescription as RegionDe2_9_ FROM Region region_ WHERE region_.RegionID=@p0;@p0 = 2 [Type: Int32 (0)] NHibernate.SQL: SELECT region_.RegionDescription as RegionDe2_9_ FROM Region region_ WHERE region_.RegionID=@p0;@p0 = 3 [Type: Int32 (0)] NHibernate.SQL: SELECT region_.RegionDescription as RegionDe2_9_ FROM Region region_ WHERE region_.RegionID=@p0;@p0 = 4 [Type: Int32 (0)] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload