Using log4net to show NHibernate SQL in Visual Studio

I’m currently developing a web application in ASP.NET MVC and NHibernate. Since the application was very slow at some points I wanted to know which SQL queries NHibernate was executing. Since the log4net library was already included in the application I searched for a solution to output the SQL queries to the console in Visual Studio 2010 using log4net. I found the solution on this wiki and this blog post.

First thing you need to do is add a log4net section in your web.config if you don’t have one yet.

Then add the log4net section, and configure an appender and logger.

That’s all. Don’t forget to configure log4net in the Global.asax.

Leave a Reply

Your email address will not be published. Required fields are marked *