Example #1
0
        [Test] public void TestSize2()
        {
            CyclicBuffer cb = new CyclicBuffer(2);

            Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
            Assert.AreEqual(2, cb.MaxSize, "Buffer should have max size 2");

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event3 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = null;

            discardedEvent = cb.Append(event1);
            Assert.IsNull(discardedEvent, "No event should be discarded after append 1");
            discardedEvent = cb.Append(event2);
            Assert.IsNull(discardedEvent, "No event should be discarded after append 2");

            discardedEvent = cb.Append(event3);
            Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");

            discardedEvent = cb.PopOldest();
            Assert.AreSame(event2, discardedEvent, "Expect event2 to now be discarded");

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
            Assert.AreSame(event3, discardedEvents[0], "Expect event3 to now be popped");
            Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
            Assert.AreEqual(2, cb.MaxSize, "Buffer should really really still have max size 2");
        }
        public void TestSize1()
        {
            CyclicBuffer cb = new CyclicBuffer(1);

            Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should have max size 1");

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = cb.Append(event1);

            Assert.IsNull(discardedEvent, "No event should be discarded untill the buffer is full");
            Assert.AreEqual(1, cb.Length, "Buffer should have length 1");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should still have max size 1");


            discardedEvent = cb.Append(event2);

            Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");
            Assert.AreEqual(1, cb.Length, "Buffer should still have length 1");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should really still have max size 1");

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
            Assert.AreSame(event2, discardedEvents[0], "Expect event2 to now be popped");
            Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
            Assert.AreEqual(1, cb.MaxSize, "Buffer should really really still have max size 1");
        }
        public void TestSize1()
        {
            CyclicBuffer cb = new CyclicBuffer(1);

            Assert.AreEqual(0, cb.Length, "空缓冲区的长度应该为0");   //Empty Buffer should have length 0
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的最大大小应该是1"); //Buffer should have max size 1

            LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
            LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);

            LoggingEvent discardedEvent = cb.Append(event1);

            Assert.IsNull(discardedEvent, "在缓冲区满之前,不应该丢弃任何事件"); //No event should be discarded untill the buffer is full
            Assert.AreEqual(1, cb.Length, "缓冲区的长度应该为1");        //Buffer should have length 1
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");     //Buffer should still have max size 1


            discardedEvent = cb.Append(event2);

            Assert.AreSame(event1, discardedEvent, "现在可以预期event1将被丢弃"); //Expect event1 to now be discarded
            Assert.AreEqual(1, cb.Length, "缓冲区的长度应该仍然为1");              //Buffer should still have length 1
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");             //Buffer should really still have max size 1

            LoggingEvent[] discardedEvents = cb.PopAll();

            Assert.AreEqual(1, discardedEvents.Length, "取出事件的长度应该是1");    //Poped events length should be 1
            Assert.AreSame(event2, discardedEvents[0], "预计event2现在会被取出"); //Expect event2 to now be popped
            Assert.AreEqual(0, cb.Length, "缓冲区的长度应该回到0");                 //Buffer should be back to length 0
            Assert.AreEqual(1, cb.MaxSize, "缓冲区的大小应该仍然是1");               //Buffer should really really still have max size 1
        }
Example #4
0
 protected virtual void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
 {
     LoggingEvent[] events = buffer.PopAll();
     if (firstLoggingEvent == null)
     {
         this.SendBuffer(events);
     }
     else if (events.Length == 0)
     {
         LoggingEvent[] eventArray1 = new LoggingEvent[] { firstLoggingEvent };
         this.SendBuffer(eventArray1);
     }
     else
     {
         LoggingEvent[] destinationArray = new LoggingEvent[] { firstLoggingEvent };
         Array.Copy(events, 0, destinationArray, 1, events.Length);
         this.SendBuffer(destinationArray);
     }
 }
 /// <summary>
 /// Sends the contents of the buffer.
 /// </summary>
 /// <param name="firstLoggingEvent">The first logging event.</param>
 /// <param name="buffer">The buffer containing the events that need to be send.</param>
 /// <remarks>
 /// <para>
 /// The subclass must override <see cref="M:SendBuffer(LoggingEvent[])" />.
 /// </para>
 /// </remarks>
 protected virtual void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
 {
     LoggingEvent[] array = buffer.PopAll();
     if (firstLoggingEvent == null)
     {
         SendBuffer(array);
         return;
     }
     if (array.Length == 0)
     {
         SendBuffer(new LoggingEvent[1]
         {
             firstLoggingEvent
         });
         return;
     }
     LoggingEvent[] array2 = new LoggingEvent[array.Length + 1];
     Array.Copy(array, 0, array2, 1, array.Length);
     array2[0] = firstLoggingEvent;
     SendBuffer(array2);
 }
 /// <summary>
 /// Flush the currently buffered events
 /// </summary>
 /// <param name="flushLossyBuffer">set to <c>true</c> to flush the buffer of lossy events</param>
 /// <remarks>
 /// <para>
 /// Flushes events that have been buffered. If <paramref name="flushLossyBuffer" /> is
 /// <c>false</c> then events will only be flushed if this buffer is non-lossy mode.
 /// </para>
 /// <para>
 /// If the appender is buffering in <see cref="P:log4net.Appender.BufferingAppenderSkeleton.Lossy" /> mode then the contents
 /// of the buffer will only be flushed if <paramref name="flushLossyBuffer" /> is <c>true</c>.
 /// In this case the contents of the buffer will be tested against the
 /// <see cref="P:log4net.Appender.BufferingAppenderSkeleton.LossyEvaluator" /> and if triggering will be output. All other buffered
 /// events will be discarded.
 /// </para>
 /// <para>
 /// If <paramref name="flushLossyBuffer" /> is <c>true</c> then the buffer will always
 /// be emptied by calling this method.
 /// </para>
 /// </remarks>
 public virtual void Flush(bool flushLossyBuffer)
 {
     lock (this)
     {
         if (m_cb != null && m_cb.Length > 0)
         {
             if (m_lossy)
             {
                 if (flushLossyBuffer)
                 {
                     if (m_lossyEvaluator != null)
                     {
                         LoggingEvent[] array     = m_cb.PopAll();
                         ArrayList      arrayList = new ArrayList(array.Length);
                         LoggingEvent[] array2    = array;
                         foreach (LoggingEvent loggingEvent in array2)
                         {
                             if (m_lossyEvaluator.IsTriggeringEvent(loggingEvent))
                             {
                                 arrayList.Add(loggingEvent);
                             }
                         }
                         if (arrayList.Count > 0)
                         {
                             SendBuffer((LoggingEvent[])arrayList.ToArray(typeof(LoggingEvent)));
                         }
                     }
                     else
                     {
                         m_cb.Clear();
                     }
                 }
             }
             else
             {
                 SendFromBuffer(null, m_cb);
             }
         }
     }
 }
        /// <summary>
        /// Sends the contents of the buffer.
        /// </summary>
        /// <param name="firstLoggingEvent">The first logging event.</param>
        /// <param name="buffer">The buffer containing the events that need to be send.</param>
        /// <remarks>
        /// <para>
        /// The subclass must override <see cref="SendBuffer(LoggingEvent[])"/>.
        /// </para>
        /// </remarks>
        virtual protected void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
        {
            LoggingEvent[] bufferEvents = buffer.PopAll();

            if (firstLoggingEvent == null)
            {
                SendBuffer(bufferEvents);
            }
            else if (bufferEvents.Length == 0)
            {
                SendBuffer(new LoggingEvent[] { firstLoggingEvent });
            }
            else
            {
                // Create new array with the firstLoggingEvent at the head
                LoggingEvent[] events = new LoggingEvent[bufferEvents.Length + 1];
                Array.Copy(bufferEvents, 0, events, 1, bufferEvents.Length);
                events[0] = firstLoggingEvent;

                SendBuffer(events);
            }
        }
Example #8
0
 /// <summary>
 /// Sends the contents of the buffer.
 /// </summary>
 /// <param name="buffer">The buffer containing the events that need to be send.</param>
 /// <remarks>
 /// The subclass must override either <see cref="SendBuffer(CyclicBuffer)"/>
 /// or <see cref="SendBuffer(LoggingEvent[])"/>.
 /// </remarks>
 virtual protected void SendBuffer(CyclicBuffer buffer)
 {
     SendBuffer(buffer.PopAll());
 }
		/// <summary>
		/// Sends the contents of the buffer.
		/// </summary>
		/// <param name="firstLoggingEvent">The first logging event.</param>
		/// <param name="buffer">The buffer containing the events that need to be send.</param>
		/// <remarks>
		/// <para>
		/// The subclass must override <see cref="M:SendBuffer(LoggingEvent[])"/>.
		/// </para>
		/// </remarks>
		virtual protected void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer)
		{
			LoggingEvent[] bufferEvents = buffer.PopAll();

			if (firstLoggingEvent == null)
			{
				SendBuffer(bufferEvents);
			}
			else if (bufferEvents.Length == 0)
			{
				SendBuffer(new LoggingEvent[] { firstLoggingEvent } );
			}
			else
			{
				// Create new array with the firstLoggingEvent at the head
				LoggingEvent[] events = new LoggingEvent[bufferEvents.Length + 1];
				Array.Copy(bufferEvents, 0, events, 1, bufferEvents.Length);
				events[0] = firstLoggingEvent;

				SendBuffer(events);
			}
		}