This is my first serious project using NHibernate and I have setup log4net to output the sql generated by NHibernate but after running my web app I cannot find any log files.
This web app is currently being run on my local machine with http://localhost/dispatch. The dispatch directory is a virtual directory in IIS pointing to a project folder in My Documents/Visual Studio 2008/Projects.
Here is the relavent portion of Web.config
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2008Dialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
my connection string
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
<log4net>
<appender name="NHibernateFileLog" type="log4net.Appender.FileAppender">
<file value="logs/nhibernate.txt" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" />
</layout>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="INFO"/>
<appender-ref ref="NHibernateFileLog"/>
</logger>
</log4net>
Also my Global.asax file looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace DispatchBoard {
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start() {
RegisterRoutes(RouteTable.Routes);
}
}
}
Please let me know what I am doing wrong. I need to see this output to debug an inefficient SQL query. Thanks.
You might have to configure the NHibernate.SQL section in web.config to have it set the level to DEBUG (but not INFO). You also are missing the NHibernate.Loader.Loader section
Here is a post that’s very helpful to enabling SQL logging for NHibernate