53

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?

ripper234
  • 222,824
  • 274
  • 634
  • 905

7 Answers7

86

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>
tinonetic
  • 7,751
  • 11
  • 54
  • 79
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
  • 2
    Not working, see updated question (I added the appropriate log4net config section, no effect). – ripper234 Sep 23 '09 at 18:42
  • 3
    log4net actually matches logger names starting with the specified name, so putting "NHibernate" will filter out every NHibernate message. – Marc Climent Jul 20 '10 at 11:47
  • I think @Ripper's comment is incorrect, this works for me and also with ActiveRecord – Chris S Dec 17 '10 at 14:35
  • 1
    @ChrisS - my comment is not incorrect. This answer works for 99% of the people, but in my case it didn't help. See http://stackoverflow.com/a/1488105/11236 – ripper234 May 22 '12 at 16:04
  • In some cases you may have to set `additivity` property to false to get what you expect, like: ` ` – Shorstok Nov 15 '16 at 08:22
14
return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                c => c.FromConnectionStringWithKey("MyDB")).ShowSql())

Removing the .ShowSql() worked for me

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
6

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

pauldendulk
  • 1,378
  • 12
  • 23
ripper234
  • 222,824
  • 274
  • 634
  • 905
4

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>
Jacob Brewer
  • 2,574
  • 1
  • 22
  • 25
2

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

2

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.

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
  • Not working (http://www.beansoftware.com/asp.net-tutorials/nhibernate-log4net.aspx). Why would the default be to show the SQL? Could it be my code somehow turns this on pragmatically? – ripper234 Sep 23 '09 at 18:38
  • Just went and checked my code. I turned it off by commenting out show_sql = true. Never mind. Sorry. – Jon Seigel Sep 23 '09 at 18:42
0

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.

Moshe Levi
  • 3,443
  • 21
  • 26