Disabling NHibernate Logging

1,089 views
Skip to first unread message

Chris Swart

unread,
Jul 17, 2015, 7:00:59 AM7/17/15
to particula...@googlegroups.com
Hi 

We are using Log4net for application logging, sadly however Persistence/NHibernate is logging out quite a bit of noise to these logs. 

I've tried disabling the NHibernate's logging by adding the following to the App.Config however this has no effect. 

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>

  <log4net>
    <logger name="NHibernate" additivity="false">
      <level value="OFF" />
    </logger>

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

However this has no effect. 

Kind Regards
Chris Swart

simon.cropp

unread,
Jul 20, 2015, 1:28:06 AM7/20/15
to particula...@googlegroups.com, illusi...@gmail.com
Chris

Can you include your bus configuration code. including how u are configuring logging?

Chris Swart

unread,
Jul 23, 2015, 8:02:51 AM7/23/15
to Particular Software, simon...@particular.net
Hi Simon 

its all done in code as a static I initialize this 

 void INeedInitialization.Customize(BusConfiguration configuration)
        {
            LoggingConfig.ConfigureAsynAdoAppender();
        } 

I then configured this in code 

Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            //hierarchy.Root.RemoveAllAppenders();

            AsyncAdoAppender sqlappender = new AsyncAdoAppender();
            sqlappender.ConnectionType = "System.Data.SqlClient.SqlConnection, System.Data,Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
            sqlappender.ConnectionString = ConfigurationManager.ConnectionStrings["AuditLogging"].ConnectionString;
            sqlappender.ReconnectOnError = true;
            sqlappender.Threshold = Level.All;
            sqlappender.QueueSizeLimit = 3000;
            sqlappender.BufferSize = 1;


There seems to be no way to get rid of the NHibernate logging as it just seem to scan is the log4net assemble is present and then just start logging. 

simon.cropp

unread,
Jul 26, 2015, 8:29:35 PM7/26/15
to Particular Software, illusi...@gmail.com, illusi...@gmail.com
Chris

Have you tried using a Log4net filter?

So you can filter log messages based on namespace. here is a sample using NSB 5 that filter out all log entries from "NServiceBus.Transports.SQLServer"

        ColoredConsoleAppender appender = new ColoredConsoleAppender
        {
            Threshold = Level.Debug,
            Layout = new SimpleLayout(),
        };

        appender.AddFilter(new LoggerMatchFilter
        {
            LoggerToMatch = "NServiceBus.Transports.SQLServer.",
            AcceptOnMatch = false
        });
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender);

        NServiceBus.Logging.LogManager.Use<Log4NetFactory>();

simon.cropp

unread,
Jul 26, 2015, 8:33:09 PM7/26/15
to Particular Software, illusi...@gmail.com, illusi...@gmail.com
I also note you are writing all log entries to sql.

Does this cause any performance overhead? 

Chris Swart

unread,
Jul 27, 2015, 5:04:42 AM7/27/15
to Particular Software, simon...@particular.net
Hi Simon 

Thanks I'll try filter appenders , but to answer your other question about 60% of your QA Environment logging seems to be NHibernate, but besides for that I use AsyncAdoAppender() so from the code point of view it adds no additional execution time, under the hood it uses a ring buffer with so in the event of being flooded with logging message the first message in get override (not ideal but better than falling over or eating up too much memory).

As for the levels, Sadly I couldn't just limited based on debug, Info etc as this we are more using this for operational logging as apposed to debugging. So in total our volumes are quite low. Lastly we've dedicated a SQL Server explicitly for this logging which helps greatly. 

Kind Regards
Chris Swart

simon.cropp

unread,
Jul 27, 2015, 11:51:14 PM7/27/15
to Particular Software, illusi...@gmail.com, illusi...@gmail.com
Chris

Just to confirm will a filter work for you?

Chris Swart

unread,
Jul 28, 2015, 4:41:45 PM7/28/15
to Particular Software, simon...@particular.net
Hi Simon 

Yes It worked thanks ! I initially started off trying to add every Logger, then i found it does a wildcard match, the below configuration seems to get rid of all the noise,  

            sqlappender.AddFilter(new LoggerMatchFilter { LoggerToMatch = "NHibernate", AcceptOnMatch = false });
            sqlappender.AddFilter(new LoggerMatchFilter { LoggerToMatch = "NServiceBus", AcceptOnMatch = false });

As a side note I needed to delete about 2m log entries from our QA logging Db, and this was over just 2 days, its strange but i never thought the Nhibernate + Outbox configuration would be so "chatty" to the database. 

Just as an off topic question but we've got secondLevelRetries on and OutBox would it be sufficient just to have InMemoryPresistance on instead of  Nhibernate (i'm not a big fan of large ORMs) 

I see all the Retries Messages get added to the RabbitMQ Queues under .Retires and these seem to persist across cluster restarts etc. 

I'm just not sure where the NHibernate Retry queues come in and why they would be needed.  

simon.cropp

unread,
Jul 29, 2015, 6:43:35 AM7/29/15
to Particular Software, illusi...@gmail.com, illusi...@gmail.com
InMemoryPresistance will result in you loosing saga and timeout data on restarts. 
Reply all
Reply to author
Forward
0 new messages