How to log SQL calls with NHibernate to the console of Visual Studio?

前端 未结 5 1128
小蘑菇
小蘑菇 2020-12-02 11:21

I have the following configuration file for NHibernate:




        
5条回答
  •  温柔的废话
    2020-12-02 11:51

    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;
    

提交回复
热议问题