Esempio n. 1
0
        /// <summary>
        /// Returns a flatten list of loggers and sub loggers that are part of this instance and its children.
        /// </summary>
        /// <returns>The flatten list.</returns>
        public IEnumerable <ILoggerFacade> Flatten()
        {
            List <AggregateLogger> aggLogList = new List <AggregateLogger>();

            aggLogList.Add(this);

            int num = 0;

            while (aggLogList.Count > num)
            {
                IList <ILoggerFacade> innerLoggers = aggLogList[num++].GetLoggers();
                for (int i = 0; i < innerLoggers.Count; i++)
                {
                    ILoggerFacade logger = innerLoggers[i];

                    AggregateLogger aggLog = logger as AggregateLogger;
                    if (aggLog != null)
                    {
                        aggLogList.Add(aggLog);
                    }
                    else
                    {
                        yield return(logger);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new instance from an inital list of loggers.
        /// </summary>
        /// <param name="loggers">The initial list of loggers to add to the new instance.</param>
        /// <returns>The new instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="loggers" /> is <see langword="null" />.
        /// </exception>
        public static AggregateLogger Create(IEnumerable <ILoggerFacade> loggers)
        {
            if (loggers == null)
            {
                throw new ArgumentNullException("loggers");
            }

            AggregateLogger result = new AggregateLogger();

            CollectionHelper.ForEach(loggers,
                                     delegate(IForEachItemExecutionContext <ILoggerFacade> ctx)
            {
                result.Add(ctx.Item);
            });

            return(result);
        }