Since replies have been light, and my reply to "why not use xml configuration"
might have been a little abrupt, let me elaborate.

I have been a log4net user almost since the first release. I have evangelized
using it for the whole time, just like I evangelized log4j to my java clients
before that. The tool is just what I want and has been really useful to me. I
hope my last post didn't lead you to think I'm anti xml or something. I think
I'm still listed on the JDOM JSR expert group, and have accepted patches in
both the crimson and xerces parsers. 

My original reason for trying this was because I was working on some code to
invoke HttpRuntime outside of IIS, and the HttpRuntime configuration system
insists on being the first caller of System.Configuration. At the time, I
understood the log4net assembly attribute as responsible for loading the
configuration system, and thought, how hard could this be to do in code. The
answer was not hard, and I got the side benefits of not having to maintain
dozens of log4net config files scattered in the flotsam and jetsam of 4 years
of development. And, it would not require any fuss when versions change, unlike
the publicpolicytoken attribute of the xml configuration file. And, I can use
injection techniques to add logging setup to my apps with minmal coding. Dang!

Then nhibernate entered the picture and decided to log on it's own, bad
behavior for a library except for debug logging IMHO.

--- Philip Nelson <[EMAIL PROTECTED]> wrote:

> 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
> 


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

Reply via email to