When you use NHibernate and asp.net one of the most interesting stuff is looking at sql generated for each page call. While NHProf is the best tool to accomplish this task, it is interesting to trace issued sql queries using asp.net trace engine.

To accomplish this task is really straightforward thanks to log4net, first of all configure a suitable appender in log4net config file.

I keep the standard level of NHIbernate to INFO, but the NHibernate.SQL to DEBUG. The result is the following.

Et voila, you get all the query that were issued to the database in the trace of your page, without the need to attach debugger or trace or whatever else. This is especially interesting if you use continuous integration and all testers usually work with latest site version running on test server. With such a facility everyone can look at what is really happening to the database.