logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject cvs commit: logging-log4net/src/Repository/Hierarchy Hierarchy.cs
Date Wed, 08 Dec 2004 20:08:12 GMT
nicko       2004/12/08 12:08:12

  Modified:    src/Repository/Hierarchy Hierarchy.cs
  Log:
  Updated GetAppenders() method to supported nested appenders
  
  Revision  Changes    Path
  1.8       +47 -7     logging-log4net/src/Repository/Hierarchy/Hierarchy.cs
  
  Index: Hierarchy.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Repository/Hierarchy/Hierarchy.cs,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Hierarchy.cs	21 Oct 2004 22:15:46 -0000	1.7
  +++ Hierarchy.cs	8 Dec 2004 20:08:12 -0000	1.8
  @@ -372,26 +372,66 @@
   		}
   
   		/// <summary>
  -		/// Returns all the Appenders that are configured as an Array.
  +		/// Returns all the Appenders that are currently configured
   		/// </summary>
  -		/// <returns>All the Appenders</returns>
  +		/// <returns>An array containing all the currently configured appenders</returns>
   		/// <remarks>
  -		/// <para>Returns all the Appenders that are configured as an Array.</para>
  +		/// <para>
  +		/// Returns all the <see cref="log4net.Appender.IAppender"/> instances that are
currently configured.
  +		/// All the loggers are searched for appenders. The appenders may also be containers
  +		/// for appenders and these are also searched for additional loggers.
  +		/// </para>
  +		/// <para>
  +		/// The list returned is unordered but does not contain duplicates.
  +		/// </para>
   		/// </remarks>
   		override public log4net.Appender.IAppender[] GetAppenders()
   		{
  -			System.Collections.ArrayList appenders = new System.Collections.ArrayList();
  +			System.Collections.ArrayList appenderList = new System.Collections.ArrayList();
  +
  +			CollectAppenders(appenderList, Root);
   
  -			appenders.AddRange(Root.Appenders);
   			foreach(Logger logger in GetCurrentLoggers())
   			{
  -				appenders.AddRange(logger.Appenders);
  +				CollectAppenders(appenderList, logger);
   			}
   
  -			return (log4net.Appender.IAppender[])appenders.ToArray(typeof(log4net.Appender.IAppender));
  +			return (log4net.Appender.IAppender[])appenderList.ToArray(typeof(log4net.Appender.IAppender));
   		}
   
   		#endregion Override Implementation of LoggerRepositorySkeleton
  +
  +		/// <summary>
  +		/// Collect the appenders from an <see cref="IAppenderAttachable"/>.
  +		/// The appender may also be a container.
  +		/// </summary>
  +		/// <param name="appenderList"></param>
  +		/// <param name="appender"></param>
  +		private static void CollectAppender(System.Collections.ArrayList appenderList, log4net.Appender.IAppender
appender)
  +		{
  +			if (!appenderList.Contains(appender))
  +			{
  +				appenderList.Add(appender);
  +
  +				if (appender is IAppenderAttachable)
  +				{
  +					CollectAppenders(appenderList, (IAppenderAttachable)appender);
  +				}
  +			}
  +		}
  +
  +		/// <summary>
  +		/// Collect the appenders from an <see cref="IAppenderAttachable"/> container
  +		/// </summary>
  +		/// <param name="appenderList"></param>
  +		/// <param name="container"></param>
  +		private static void CollectAppenders(System.Collections.ArrayList appenderList, IAppenderAttachable
container)
  +		{
  +			foreach(log4net.Appender.IAppender appender in container.Appenders)
  +			{
  +				CollectAppender(appenderList, appender);
  +			}
  +		}
   
   		#region Implementation of IBasicRepositoryConfigurator
   
  
  
  

Mime
View raw message