Search code examples
c#-4.0fluent-nhibernatelog4netnhibernate-3

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.


Solution

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