views:

1130

answers:

5

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?

+5  A: 

This link 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>
kgiannakakis
Not working, see updated question (I added the appropriate log4net config section, no effect).
ripper234
+1, it was helpful to me!
RichardOD
log4net actually matches logger names starting with the specified name, so putting "NHibernate" will filter out every NHibernate message.
Marc Climent
A: 

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
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
Just went and checked my code. I turned it off by commenting out show_sql = true. Never mind. Sorry.
Jon Seigel
A: 

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
A: 

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

ripper234
+1  A: 

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

removing the .ShowSql() worked for me

BobTodd