Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 92550 invoked from network); 13 Dec 2005 17:02:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Dec 2005 17:02:38 -0000 Received: (qmail 6335 invoked by uid 500); 13 Dec 2005 14:12:23 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 6311 invoked by uid 500); 13 Dec 2005 14:12:23 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 6299 invoked by uid 99); 13 Dec 2005 14:12:22 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2005 06:12:22 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of nicko@neoworks.com designates 80.168.17.114 as permitted sender) Received: from [80.168.17.114] (HELO hermes.neoworks.co.uk) (80.168.17.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2005 06:12:21 -0800 Received: from kronos.neoworks.co.uk (kronos.neoworks.co.uk [10.0.0.132]) by hermes.neoworks.co.uk (8.13.1/8.13.1) with ESMTP id jBDE6kN3002887 for ; Tue, 13 Dec 2005 14:06:48 GMT Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Programatically changing the logger for NHibernate X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Date: Tue, 13 Dec 2005 14:11:54 -0000 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Programatically changing the logger for NHibernate Thread-Index: AcX0PNULa9DBeYGsToayyCu6REKqUwLsf7PA From: "Nicko Cadell" To: "Log4NET User" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Philip, Rather than use a Filter, there is a more performant option, which is to set the level on the NHibernate logger. By default this will be inherited by the child loggers, i.e. all of the NHibernate loggers. To do this in code you can do: ((log4net.Repository.Hierarchy.Logger)LogManager.GetLogger("NHibernate") .Logger).Level =3D Level.Off; While there are advantages to configuring log4net programmatically this sort of logger hierarchy is much easier to see in the XML config file. Cheers, Nicko > -----Original Message----- > From: Philip Nelson [mailto:panmanphil@yahoo.com]=20 > Sent: 28 November 2005 16:57 > To: Log4NET User > Subject: Re: Programatically changing the logger for NHibernate >=20 > And this did the trick. I tried to use the PropertyFilter=20 > directly, but I couldn't come up with the property key that=20 > represented LoggerName. I tried loggername, LoggerName,=20 > logger, Logger, log4net:logger and log4net:loggername >=20 > class NHibernateFilter : StringMatchFilter { > public override FilterDecision Decide(LoggingEvent loggingEvent) > { > FilterDecision decision =3D FilterDecision.Accept; > if (loggingEvent.LoggerName.StartsWith("NHibernate")) > decision =3D FilterDecision.Deny; > =09 > return decision; > } >=20 > } >=20 > Thanks for your help! >=20 > --- Philip Nelson wrote: >=20 > > I'll look into it, thanks. > >=20 > > --- DWilliams@strohlsystems.com wrote: > >=20 > > > I would think that you could set up a filter to exclude the=20 > > > NHibernate logs. Looking at the code however implies=20 > that you might=20 > > > have to write a not assembly filter. > > >=20 > > >=20 > > >=20 > > >=20 > > > =20 > =20 > > > Philip Nelson =20 > =20 > > > =20 > > > .com> =20 > To=20 > > > Log4NET User =20 > =20 > > > 11/28/2005 08:40 =20 > =20 > > > AM =20 > cc=20 > > > =20 > =20 > > > =20 > Subject=20 > > > Please respond to Re:=20 > Programatically changing the =20 > > > "Log4NET User" logger for=20 > NHibernate =20 > > > =20 > > > ging.apache.org> =20 > =20 > > > =20 > =20 > > > =20 > =20 > > > =20 > =20 > > > =20 > =20 > > >=20 > > >=20 > > >=20 > > >=20 > > > Since replies have been light, and my reply to "why not use xml=20 > > > configuration" > > > might have been a little abrupt, let me elaborate. > > >=20 > > > I have been a log4net user almost since the first release. I have=20 > > > evangelized using it for the whole time, just like I evangelized=20 > > > log4j to my java clients before that. The tool is just=20 > what I want=20 > > > and has been really useful to me. > > > I > > > hope my last post didn't lead you to think I'm anti xml or=20 > > > something. I think I'm still listed on the JDOM JSR expert group,=20 > > > and have accepted patches in both the crimson and xerces parsers. > > >=20 > > > My original reason for trying this was because I was=20 > working on some=20 > > > code to invoke HttpRuntime outside of IIS, and the HttpRuntime=20 > > > configuration system insists on being the first caller of=20 > > > System.Configuration. At the time, I understood the=20 > log4net assembly=20 > > > attribute as responsible for loading the configuration=20 > system, and=20 > > > 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=20 > > > maintain dozens of log4net config files scattered in the=20 > flotsam and=20 > > > jetsam of 4 years of development. And, it would not=20 > require any fuss=20 > > > when versions change, unlike the publicpolicytoken=20 > attribute of the=20 > > > xml configuration file. And, I can use injection=20 > techniques to add=20 > > > logging setup to my apps with minmal coding. > > > Dang! > > >=20 > > > Then nhibernate entered the picture and decided to log on=20 > it's own,=20 > > > bad behavior for a library except for debug logging IMHO. > > >=20 > > > --- Philip Nelson wrote: > > >=20 > > > > I had added a configuration that built my loggers in=20 > code only and=20 > > > > all > > > was > > > > well > > > > (no xml!). Later though, I found out that NHibernate is doing=20 > > > > something > > > bad, > > > > logging exceptions with log.Error. These exceptions are=20 > handled by=20 > > > > the caller, so I really don't want those log calls made=20 > at all. No=20 > > > > problem, I thought > > > I'd > > > > create a repository for the NHibernate assembly, setup the=20 > > > > appender I > > > want, > > > > and > > > > this would get used instead of my default logger that=20 > sends emails=20 > > > > on > > > error. > > > > > > > > ILoggerRepository logger =3D Reset(); //the normal logger > > > > > > > > string pattern =3D "%d %-5p %c %x - %m%n"; string filename =3D=20 > > > > Path.Combine(_logPath, LogFileName); string debugFilename =3D=20 > > > > Path.Combine(_logPath + "debug/", LogFileName); > > > > > > > > //setup nhibernate logger separately so it will not=20 > email errors=20 > > > > Type nType =3D AppContext.ActiveSession.GetType(); //gets the=20 > > > > NHibernate ISession Assembly nhib =3D nType.Assembly;=20 > > > > ILoggerRepository nrep =3D null; ILogger l =3D=20 > > > > LoggerManager.GetLogger(nhib, nType); nrep =3D l.Repository;=20 > > > > nrep.ResetConfiguration(); ForwardingAppender dbgAppender =3D = new=20 > > > > ForwardingAppender();=20 > > > > dbgAppender.AddAppender(setupDebugAppender(pattern,=20 > > > > Path.Combine(_logPath > > > + > > > > "debug/NHib", LogFileName))); > > > > log4net.Config.BasicConfigurator.Configure(nrep, dbgAppender); > > > > > > > > My assumption was that the normal logger repository, "logger"=20 > > > > would now > > > not > > > > be > > > > used because NHibernate gets its logger with=20 > > > > LogManager.GetLogger(typeof(this)). > > > > > > > > The new logger logs correctly, but the original logger=20 > also logs,=20 > > > > so my > > > goal > > > > of > > > > getting rid of the emails wasn't met. > > > > > > > > Any ideas about how to cheat NHibernate of it's logging? > > > > > > > > Philip -=20 > > > > http://www.xcskiwinn.org/community/blogs/panmanphil/default.aspx > > > > "Now that was a bad vowel movement" - Barbara > > > > > > >=20 > > >=20 > > > Philip -=20 > > > http://www.xcskiwinn.org/community/blogs/panmanphil/default.aspx > > > "Now that was a bad vowel movement" - Barbara > > >=20 > > >=20 > > >=20 > >=20 > >=20 > > Philip -=20 > > http://www.xcskiwinn.org/community/blogs/panmanphil/default.aspx > > "Now that was a bad vowel movement" - Barbara > >=20 >=20 >=20 > Philip -=20 > http://www.xcskiwinn.org/community/blogs/panmanphil/default.aspx > "Now that was a bad vowel movement" - Barbara >=20