Wednesday, April 15, 2009

Send all NHibernate SQL queries to console output

When using a separate XML file to configure NHibernate (e.g. the hibernate.cfg.xml):
<?xml version="1.0" encoding="utf-8" ?>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Server=(local);Database=NHibernateFAQ;Integrated Security=SSPI;</property>
      <property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
When using ActiveRecord and Web.config:
<configuration>
  <configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
  </configSections>
  <appSettings>
  </appSettings>
  <activerecord>
    <config>
      <add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />
      <add key="hibernate.dialect" value="NHibernate.Dialect.OracleDialect" />
      <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="hibernate.connection.connection_string" value="Data Source=sss;User ID=uuu;Password=ppp;" />
      <add key="hibernate.show_sql" value="true" />
    </config>
  </activerecord>
</configuration>
Thanks to: http://nhforge.org/wikis/howtonh/configure-log4net-for-use-with-nhibernate.aspx.

No comments: