Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set Nhibernate to lower logging level for log4net

I have an application which logs to log4net but also uses Nhibernate. My app configures both Nhibernate (using Fluent Nhibernate config) and log4Net (using BasicConfigurator) programmatically .

Problem is my logs are full of Nhibernate log info which I don't need 99.9% of the time and the app slows down due to the full logging from Nhibernate.

How can I configure Nihbernate to not do any logging or log4Net to ignore all Nhibernate loggers programmatically? I know you can do it using xml config files but this is not an option for me.

Any help would be much appreciated.

like image 860
Richard Avatar asked Oct 27 '25 19:10

Richard


1 Answers

See Log4Net: Programmatically specify multiple loggers (with multiple file appenders) where I stole this from:

public static void SetLevel(string loggerName, string levelName)
{
    ILog log = LogManager.GetLogger(loggerName);
    Logger l = (Logger)log.Logger;

    l.Level = l.Hierarchy.LevelMap[levelName];
}


SetLevel("NHibernate","Error");
like image 193
Preet Sangha Avatar answered Oct 31 '25 12:10

Preet Sangha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!