Richard
Richard

Reputation: 22016

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.

Upvotes: 4

Views: 1288

Answers (1)

Preet Sangha
Preet Sangha

Reputation: 65476

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");

Upvotes: 8

Related Questions