禁用NHibernate调试(dbug)日志输出

时间:2019-03-26 16:43:50

标签: nhibernate

在Visual Studio 2017和NHibernate 5.2.4中运行this example ASP.NET Core web app。像这样配置:

public NhibernateSessionFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, IAppConfig config)
{
    NHibernateLogger.SetLoggersFactory(new 
        NHibernateToMicrosoftLoggerFactory(loggerFactory));

    Configuration = new Configuration();

Configuration.DataBaseIntegration(db =>
{
    db.ConnectionString = config.SqlConnectionString;
    db.Dialect<MsSql2008Dialect>();
    db.Driver<Sql2008ClientDriver>();

    db.AutoCommentSql = false;
    db.LogSqlInConsole = false;
    db.LogFormattedSql = false;

}).AddMapping(domainMapping);

App运行正常,但是ASP.NET Core Web Server的输出严重充满了NHibernate的调试条目,这是输出的一小部分采样:

dbug: NHibernate.AdoNet.ConnectionManager[0]
After autocommit
dbug: NHibernate.Impl.SessionImpl[0]
transaction completion
dbug: NHibernate.Event.Default.DefaultLoadEventListener[0]

dbug: NHibernate.Impl.SessionFactoryImpl[0]
Instantiated session factory
dbug: NHibernate.Impl.SessionFactoryImpl[0]
Checking 0 named HQL queries
dbug: NHibernate.Impl.SessionFactoryImpl[0]
Checking 0 named SQL queries
dbug: NHibernate.Impl.SessionFactoryImpl.SessionBuilderImpl[0]
Opening Hibernate Session.
dbug: NHibernate.Impl.SessionImpl[0]
[session-id=9702f8cd-942c-48ca-b68f-c8f1f7e012fb] opened session at timestamp: 636891853094, for session factory: [(null)/e85a992abde44debab0abed34c563e68]

Release模式下运行应用程序,dbug条目仍会显示。反正要禁用它们?

更新:注释掉此行是可行的,但这是推荐的方法吗?

NHibernateLogger.SetLoggersFactory(new NHibernateToMicrosoftLoggerFactory(loggerFactory));

0 个答案:

没有答案