views:

2761

answers:

3

I have the following configuration file for NHibernate:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.connection_string">Server=.\SQLEXPRESS;Database=mydb;Integrated Security=True;</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.release_mode">auto</property>
    <property name="adonet.batch_size">500</property>

    <property name="show_sql">true</property>

  </session-factory>
</hibernate-configuration>

But the SQL doesn't show in the output window of Visual Studio. Is it mandatory to install log4net? Or should show_sql work alone?

+4  A: 

show_sql outputs to Console.Out - it's most useful when running integration tests

Matt Hinze
does it mean no way to see it in VS? Does it mean I must install log4net?
Nicolas Cadilhac
TestDriven.NET sends Console.Out to the output window in VS. That's how I use show_sql
Matt Hinze
+4  A: 

There is something called NHibernate profiler you can use.

http://nhprof.com/

it's pricey but it works and it has a 30 day trial.

Sara Chipps
+7  A: 

To show the SQL in the output window of Visual Studio, configure log4net to use TraceAppender in your log4net config. This:

<appender name="DebugSQL" type="log4net.Appender.TraceAppender">
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

Then this:

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

EDIT: I can't seem to format this correctly here. See this link for code example

LordHits