I found a some post about difficulties found on logging sql queries when using NHibernate 3.x
Indeed I’m using NHibernate 3.2 and I can’t get the sql logging to work.
I just need the simple logging capabilities that write in the output window when testing or debugging.
It used to work in NH 2.2, but with this new version something is wrong.
As this article says, I simply configured NHibernate with
<property name="show_sql">true</property>
I have this simple code:
using (var session = PersistenceManager.Istance.GetSession()) {
var result = (from agenzia in session.Query<Agenzia>()
select agenzia).ToList();
return result;
}
But it seems that nothing is retrieved from the DB. So I don’t know if nothing is logged (I’m debugging under visual studio 2010, so I expect to see something in the output window), or simply nothing is even executed for some strange reason.
There’s no exception anywhere, so I’m a little confused
EDITED:
as requested, this is the complete configuration file for NHibernate:
<?xml version="1.0" encoding="utf-8" ?>
<!-- NHibernate Configuration -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.xlns">
<property name="dialect">
NHibernate.Dialect.MsSql2000Dialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
the flag show_sql, AFAIK logs on the STDOUT, so it works perfectly in unit test, or console application, but it does nothing if your app is without stdout ( ie winapp or web app ) in such a case you should enable the log
NHibernate.SQLin the log4net config ( or in the alternative logger you possibly use). In a web app you can configure a trace appender in order to see the logged query in the trace window of the debugger.