Logging NHibernate SQL queries

后端 未结 4 1213
执笔经年
执笔经年 2021-02-07 14:25

Is there a way to access the full SQL query, including the values, inside my code?

I am able to log SQL queries using log4net:



        
4条回答
  •  半阙折子戏
    2021-02-07 14:54

    you can use an interceptor to do this:

    public class LoggingInterceptor : EmptyInterceptor {
        public override SqlString OnPrepareStatement(SqlString sql) {
    
            Debug.WriteLine(sql);
    
            return sql;
        }
    }
    

    See Nhibernate Docs for the different ways to register it with nhibernate.

提交回复
热议问题