1

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?

Community
  • 1
  • 1
hardywang
  • 4,864
  • 11
  • 65
  • 101
  • @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

2 Answers2

4

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.

Toni Parviainen
  • 2,217
  • 1
  • 16
  • 15
1

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.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115