Take the 2-minute tour ×

This question is almost the same as Intercept SQL statements containing parameter values generated by NHibernate but with no answer so far yet.

Public Class SqlStatementInterceptor
    Inherits EmptyInterceptor
    Implements IInterceptor

    Public Overrides Function OnPrepareStatement(sql As SqlString) As SqlString
        Debug.WriteLine(String.Format("{0} - {1}", DateTime.Now, sql.ToString()))
        Return sql
    End Function
End Class

I can capture SQL statementm, but does not seem to be able to get parameters. Anybody ever tried to achieve it?

share|improve this question
cant you use the logger ? –  Felice Pollano Dec 28 '11 at 16:53
@Felice Pollano I could, but not ideal. Because I implement unit test by using SQLite (in production code I use SQL Server), it might be faster to show the statement in VS output window. –  hardywang Dec 28 '11 at 17:38
you can, have a look at the reply. No needing to create a special appender if you just want to see what happens –  Felice Pollano Dec 28 '11 at 18:19
add comment

2 Answers

You need to write log4net appender. This is how NHProf gets the information. There is also project on codeplex called NHibernate 3.0 SQL Logger which uses that technique.

share|improve this answer
add comment

You can use log4net with a TraceAppender, and also the format_sql=true property in configuration that help in readability. The logger to use is NHibernate.SQL.

share|improve this answer
add comment

Your Answer


