Disable NHibernate logging

2020-05-19 13:48发布

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?

7条回答
一纸荒年 Trace。
2楼-- · 2020-05-19 14:13

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>
查看更多
仙女界的扛把子
3楼-- · 2020-05-19 14:20

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

查看更多
劫难
4楼-- · 2020-05-19 14:22

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>
查看更多
劳资没心,怎么记你
5楼-- · 2020-05-19 14:25

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.

查看更多
6楼-- · 2020-05-19 14:27

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

查看更多
做自己的国王
7楼-- · 2020-05-19 14:30

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.

查看更多
登录 后发表回答