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: inheritance of appenders from Parent
Date Fri, 02 Sep 2005 10:57:08 GMT
The Logger.GetAppender method does not get inherited appenders. It only
returns appenders defined on the Logger istelf.

To get all the appenders you need to look at all the parent loggers as
well:

Appender FindAppender(Logger log, string appenderName)
{
  for(Logger l=log; l!=null; l=l.Parent)
  {
    Appender a=l.GetAppender(appenderName);
    if (a != null)
    {
      return a;
    }
    if(!l.Additivity)
    {
      break;
    }
  }
  return null;
}

Cheers,
Nicko

> -----Original Message-----
> From: Shaily Goel [mailto:gshaily@novell.com] 
> Sent: 02 September 2005 10:58
> To: log4net-user@logging.apache.org; Nicko Cadell
> Subject: inheritance of appenders from Parent
> 
> Hi
>  
> I am facing a problem in inheritance of appenders from Parent. 
>  
> version of Log4net used: incubating-log4net-1.2.9-beta ;
> Platform: Windows 
>  
> Test: Test if logger a.b inherits its appender from a.
>  
> static void Main(string[] args)
>   {   
>        
>             Logger a = LogManager.GetLogger("a").Logger as Logger;
>             a.Additivity = true;
>             a.Repository.Configured = true; 
>             
>             ConsoleAppender ca = new ConsoleAppender();
>             ca.Name = "Test";              
>             ca.ActivateOptions();
>             
>             a.AddAppender(ca);
>             Logger ab = LogManager.GetLogger("a.b").Logger as 
> Logger;  
>             IAppender ar = ab.GetAppender("Test"); }
>  
> I found that there is no appender inherited by Logger a.b. 
> Why is it so?
>  
> What should I do to make "a.b" inherits all the appender of "a".
>  
> Thanks
> Shaily
> 
>  
> 

Mime
View raw message