logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: filtering on message source
Date Tue, 13 Dec 2005 15:41:43 GMT
You have a separate Logger for each class (i.e. a separate ILog
interface). If you just want to see the log output from 2 specific
loggers you can do:

<appender name="MyAppender">
  ...
</appender>

<root>
  <level value="OFF" /> <!-- By default we don't want to see any output
-->
  <appender-ref name="MyAppender" />
</root>

<logger name="Company.Project.UI.Login">
  <level value="WARN"/>
</logger>
<logger name="Company.Project.UI.Logout">
  <level value="WARN"/>
</logger>


No need for filters if you just want cut a section through the Logger
hierarchy. Its performant too.

Cheers,
Nicko

> -----Original Message-----
> From: Dalton, Barnaby [mailto:Barnaby.Dalton@brevanhoward.com] 
> Sent: 08 December 2005 08:06
> To: Log4NET User
> Subject: RE: filtering on message source
> 
> 
> Thanks,
> Do I need to create a logger named 
> Company.Project.UI.Login/Logout or does logger refer to a 
> classname and will work with only a root logger defined? 
> 
> Barney
> 
> > -----Original Message-----
> > From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
> > Sent: Tuesday 06 December 2005 23:51
> > To: Log4NET User
> > Subject: Re: filtering on message source
> > 
> > 
> > Here's how to use it:
> > 
> >  <filter type="Company.Project.Logging.CustomFilter">
> >   <logLevelEqualOrAbove value="WARN" />
> >   <allMessagesFromLogger value="Company.Project.UI.Login" />
> >   <allMessagesFromLogger value="Company.Project.UI.Logout" />  
> > </filter>  <filter type="log4net.Filter.DenyAllFilter" />
> > 
> > --- Ron Grabowski <rongrabowski@yahoo.com> wrote:
> > 
> > > public class CustomFilter : FilterSkeleton {  private Level 
> > > logLevelEqualOrAbove = Level.All;  private Hashtable 
> > > acceptAllMessagesLookup = new Hashtable();
> > > 
> > >  public override FilterDecision Decide(LoggingEvent 
> loggingEvent)  {
> > >   if (acceptAllMessagesLookup.Contains(loggingEvent.LoggerName))
> > >   {
> > >    return FilterDecision.Accept;
> > >   }
> > >   else
> > >   {
> > >    if (Level.Compare(loggingEvent.Level,LogLevelEqualOrAbove)>=0)
> > >    {
> > >     return FilterDecision.Accept;
> > >    }
> > >    else
> > >    {
> > >     return FilterDecision.Deny;
> > >    }
> > >   }
> > >  }
> > > 
> > >  public Level LogLevelEqualOrAbove
> > >  {
> > >   get { return logLevelEqualOrAbove; }
> > >   set { logLevelEqualOrAbove = value; }  }
> > > 
> > >  public void AddAllMessagesFromLogger(string logger)  {
> > >   acceptAllMessagesLookup[logger] = null;  } }
> >
> 

Mime
View raw message