How to log SQL calls with NHibernate to the console of Visual Studio?
To show the SQL in the output window of Visual Studio, configure log4net to use TraceAppender in your log4net config. This:
<appender name="DebugSQL" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
Then this:
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="DebugSQL" />
</logger>
EDIT: I can't seem to format this correctly here. See this link for code example
For those who prefer code rather than configuration, the following snippet will create the appropriate NH logger with a simple console appender.
var hierarchy = (Hierarchy) LogManager.GetRepository();
var logger = (Logger) hierarchy.GetLogger("NHibernate.SQL");
logger.AddAppender(new ConsoleAppender {Layout = new SimpleLayout()});
hierarchy.Configured = true;