Logging NHibernate SQL queries

后端 未结 4 1079
执笔经年
执笔经年 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:49

    You can override driver:

    public class LoggerSqlClientDriver:SqlClientDriver, IEmbeddedBatcherFactoryProvider
    {      
        public override void AdjustCommand(IDbCommand command)
        {
            //log here
            base.AdjustCommand(command);
        }
    
        //protected override void OnBeforePrepare(IDbCommand command)
        //{
        //    //log here
        //    base.OnBeforePrepare(command);
        //}
    }
    

    And then use it in configuration:

    var config = Fluently.Configure().
                Database(MsSqlConfiguration.MsSql2005.Driver();
    

提交回复
热议问题