コード例 #1
0
        // Protected Methods (1) 

        /// <inheriteddoc />
        protected override void OnLog(ILogMessage msg)
        {
            List <Exception> occuredExceptions = new List <Exception>();
            bool             throwExceptions   = false;
            int index = 0;

            using (IEnumerator <ILoggerFacade> e = this._FALLBACK_LOGGERS.GetEnumerator())
            {
                ILoggerFacade currentLogger = this._INNER_LOGGER;
                while (currentLogger != null)
                {
                    bool searchForNextFallback = false;
                    throwExceptions = false;

                    try
                    {
                        if (currentLogger.Log(msg) == false)
                        {
                            throw new Exception(string.Format("Logger #{0} ({1}; {2}) failed!",
                                                              index,
                                                              currentLogger.GetType().FullName,
                                                              currentLogger.GetHashCode()));
                        }
                    }
                    catch (Exception ex)
                    {
                        searchForNextFallback = true;
                        throwExceptions       = true;

                        occuredExceptions.Add(ex);
                    }
                    finally
                    {
                        currentLogger = null;
                    }

                    if (searchForNextFallback)
                    {
                        if (e.MoveNext())
                        {
                            currentLogger = e.Current;
                            ++index;
                        }
                    }
                }
            }

            if (throwExceptions)
            {
                throw new AggregateException(occuredExceptions);
            }
        }