4

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.

Richard
  • 21,728
  • 13
  • 62
  • 101

1 Answers1

8

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");
Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216