Disable NHibernate logging

NhibernateLoggingLog4net

Nhibernate Problem Overview


I have an empty app.config file, but I still get NHibernate debug logs

NHibernate: SELECT this_.LogID as LogID71_0_, this_.Level as Level71_0_, this_.Message as Message71_0_, this_.EventTime as EventTime71_0_, this_.Component as ...

I tried adding a log4net configuration with an ERROR log level, but no use. How can I stop these log messages?

The thing I'm puzzled about is why do these appear in the first place if I have an empty app.config to being with. It doesn't make sense to me that I have to configure it not to print these messaages - the default should be off. Could it be my code is setting them on programatically somehow? What should I look for?

Nhibernate Solutions


Solution 1 - Nhibernate

Configure Log4Net for use with NHibernate may be helpful.

You need to have both these loggers:

 <logger name="NHibernate">
   <level value="ERROR" />
 </logger>

 <logger name="NHibernate.SQL">
   <level value="ERROR" />
 </logger>

Solution 2 - Nhibernate

return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                c => c.FromConnectionStringWithKey("MyDB")).ShowSql())

Removing the .ShowSql() worked for me

Solution 3 - Nhibernate

The problem was somewhere in "my code". We build the NHibernate configuration manually (setting the show_sql flag to true).

Solution 4 - Nhibernate

The NHibernate logs don't help me much... I like these settings better:

    <logger name="NHibernate">
      <level value="OFF" />
    </logger>

    <logger name="NHibernate.SQL">
      <level value="OFF" />
    </logger>

Solution 5 - Nhibernate

Do you want to disable the logging at the NHibernate level or the Log4Net level?

I'm doing the former by setting "show_sql" variable to false. I'm doing this programmatically in C# right now, but I assume this would be easy to put in an XML configuration file as well.

Solution 6 - Nhibernate

For me it was the NUnit problem. The extra logging was happening when running the tests in TeamCity which must have been using a different version of nunit

Solution 7 - Nhibernate

Are you using NUnit 2.4.6? I read this blog post yesterday which says that this version of NUnit sets log4net to use DEBUG level logging, effecting NHibernate as well.

if it's not NUnit and it's not you, I would check if it's some other 3rd party library that you're using.

EDIT

On second thought, I don't think that the output has something to do with log4net. the format looks more like the "show_sql" controlled output. I would check two things:

  1. If the correct (the one with the show_sql=false) hibernate.config is copied to your execution directory.
  2. If the show_sql configuration property is not overridden manually in your code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionripper234View Question on Stackoverflow
Solution 1 - NhibernatekgiannakakisView Answer on Stackoverflow
Solution 2 - Nhibernatejenson-button-eventView Answer on Stackoverflow
Solution 3 - Nhibernateripper234View Answer on Stackoverflow
Solution 4 - NhibernateJacob BrewerView Answer on Stackoverflow
Solution 5 - NhibernateJon SeigelView Answer on Stackoverflow
Solution 6 - Nhibernateuser1891762View Answer on Stackoverflow
Solution 7 - NhibernateMoshe LeviView Answer on Stackoverflow