I had added a configuration that built my loggers in code only and all was well
(no xml!). Later though, I found out that NHibernate is doing something bad,
logging exceptions with log.Error. These exceptions are handled by the caller,
so I really don't want those log calls made at all. No problem, I thought I'd
create a repository for the NHibernate assembly, setup the appender I want, and
this would get used instead of my default logger that sends emails on error.

ILoggerRepository logger = Reset(); //the normal logger
                        
string pattern = "%d %-5p %c %x - %m%n";
string filename = Path.Combine(_logPath, LogFileName);
string debugFilename = Path.Combine(_logPath + "debug/", LogFileName);
                        
//setup nhibernate logger separately so it will not email errors
Type nType = AppContext.ActiveSession.GetType(); //gets the NHibernate ISession
Assembly nhib = nType.Assembly;
ILoggerRepository nrep = null;
ILogger l = LoggerManager.GetLogger(nhib, nType);
nrep = l.Repository;
nrep.ResetConfiguration();
ForwardingAppender dbgAppender = new ForwardingAppender();      
dbgAppender.AddAppender(setupDebugAppender(pattern, Path.Combine(_logPath +
"debug/NHib", LogFileName)));
log4net.Config.BasicConfigurator.Configure(nrep, dbgAppender);

My assumption was that the normal logger repository, "logger" would now not be
used because NHibernate gets its logger with
LogManager.GetLogger(typeof(this)).

The new logger logs correctly, but the original logger also logs, so my goal of
getting rid of the emails wasn't met.

Any ideas about how to cheat NHibernate of it's logging?

Philip - http://www.xcskiwinn.org/community/blogs/panmanphil/default.aspx
"Now that was a bad vowel movement" - Barbara

Reply via email to