Exemplo n.º 1
0
 /// <summary>
 /// Append on on all attached appenders.
 /// </summary>
 /// <param name="loggingEvent">The event being logged.</param>
 /// <returns>The number of appenders called.</returns>
 /// <remarks>
 /// <para>
 /// Calls the <see cref="M:log4net.Appender.IAppender.DoAppend(log4net.Core.LoggingEvent)" /> method on all
 /// attached appenders.
 /// </para>
 /// </remarks>
 public int AppendLoopOnAppenders(LoggingEvent loggingEvent)
 {
     if (loggingEvent == null)
     {
         throw new ArgumentNullException("loggingEvent");
     }
     if (m_appenderList == null)
     {
         return(0);
     }
     if (m_appenderArray == null)
     {
         m_appenderArray = m_appenderList.ToArray();
     }
     IAppender[] appenderArray = m_appenderArray;
     foreach (IAppender appender in appenderArray)
     {
         try
         {
             appender.DoAppend(loggingEvent);
         }
         catch (Exception exception)
         {
             LogLog.Error(declaringType, "Failed to append to appender [" + appender.Name + "]", exception);
         }
     }
     return(m_appenderList.Count);
 }
        public void ToArrayTest()
        {
            AppenderCollection appenderCollection = new AppenderCollection();
            IAppender          appender           = new AppenderMemory();

            appenderCollection.Add(appender);

            IAppender[] appenderArray = appenderCollection.ToArray();

            Assert.AreEqual(1, appenderArray.Length);
            Assert.AreEqual(appender, appenderArray[0]);
        }
        public void ReadOnlyToArrayTest()
        {
            AppenderCollection appenderCollection = new AppenderCollection();
            IAppender          appender           = new AppenderMemory();

            appenderCollection.Add(appender);
            AppenderCollection readonlyAppenderCollection = AppenderCollection.ReadOnly(appenderCollection);

            IAppender[] appenderArray = readonlyAppenderCollection.ToArray();

            Assert.AreEqual(1, appenderArray.Length);
            Assert.AreEqual(appender, appenderArray[0]);
        }