Ejemplo n.º 1
0
        private void LazyWriterTimerCallback(object state)
        {
            lock (_inLazyWriterMonitor)
            {
                try
                {
                    do
                    {
                        // Console.WriteLine("q: {0}", RequestQueue.RequestCount);
                        List <LogEventInfo> pendingRequests = RequestQueue.DequeueBatch(BatchSize);

                        try
                        {
                            if (pendingRequests.Count == 0)
                            {
                                break;
                            }

                            LogEventInfo[] events = pendingRequests.ToArray();
                            WrappedTarget.Write(events);
                        }
                        finally
                        {
                            RequestQueue.BatchProcessed(pendingRequests);
                        }
                    } while (_flushAll);
                }
                catch (Exception ex)
                {
                    InternalLogger.Error("Error in lazy writer timer procedure: {0}", ex);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Changes the security context, forwards the call to the <see cref="WrapperTargetBase.WrappedTarget"/>.Write()
 /// and switches the context back to original.
 /// </summary>
 /// <param name="logEvents">Log events.</param>
 public override void Write(LogEventInfo[] logEvents)
 {
     using (DoImpersonate())
     {
         WrappedTarget.Write(logEvents);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Forwards the log message to the <see cref="WrapperTargetBase.WrappedTarget"/> by calling the <see cref="Target.Write(LogEventInfo)"/> method <see cref="RepeatCount"/> times.
 /// </summary>
 /// <param name="logEvent">The log event.</param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     for (int i = 0; i < RepeatCount; ++i)
     {
         WrappedTarget.Write(logEvent);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Changes the security context, forwards the call to the <see cref="WrapperTargetBase.WrappedTarget"/>.Write()
 /// and switches the context back to original.
 /// </summary>
 /// <param name="logEvents">Log events.</param>
 protected internal override void Write(LogEventInfo[] logEvents)
 {
     using (DoImpersonate())
     {
         WrappedTarget.Write(logEvents);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Writes the specified log event to the wrapped target, retrying and pausing in case of an error.
 /// </summary>
 /// <param name="logEvent">The log event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     for (int i = 0; i < RetryCount; ++i)
     {
         try
         {
             if (i > 0)
             {
                 InternalLogger.Warn("Retry #{0}", i);
             }
             WrappedTarget.Write(logEvent);
             // success, return
             return;
         }
         catch (Exception ex)
         {
             InternalLogger.Warn("Error while writing to '{0}': {1}", WrappedTarget, ex);
             if (i == RetryCount - 1)
             {
                 throw ex;
             }
             System.Threading.Thread.Sleep(RetryDelayMilliseconds);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Forwards the log message to the <see cref="WrapperTargetBase.WrappedTarget"/> by calling the <see cref="Target.Write(LogEventInfo)"/> method <see cref="RepeatCount"/> times.
 /// </summary>
 /// <param name="logEvent">The log event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     for (int i = 0; i < RepeatCount; ++i)
     {
         WrappedTarget.Write(logEvent);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks the condition against the passed log event.
        /// If the condition is met, the log event is forwarded to
        /// the wrapped target.
        /// </summary>
        /// <param name="logEvent">Log event.</param>
        public override void Write(LogEventInfo logEvent)
        {
            object v = _condition.Evaluate(logEvent);

            if (v != null && v is bool && (bool)v)
            {
                WrappedTarget.Write(logEvent);
            }
        }
Ejemplo n.º 8
0
 void FlushCallback(object state)
 {
     lock (this)
     {
         LogEventInfo[] events = _buffer.GetEventsAndClear();
         if (events.Length > 0)
         {
             WrappedTarget.Write(events);
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Flushes pending events in the buffer (if any).
        /// </summary>
        public override void Flush(TimeSpan timeout)
        {
            base.Flush(timeout);

            lock (this)
            {
                LogEventInfo[] events = _buffer.GetEventsAndClear();
                if (events.Length > 0)
                {
                    WrappedTarget.Write(events);
                }
            }
        }
        private void OnEndRequest(object sender, EventArgs args)
        {
            LogEventInfoBuffer buffer = GetRequestBuffer();

            if (buffer != null)
            {
                LogEventInfo[] events = buffer.GetEventsAndClear();
                if (events.Length > 0)
                {
                    WrappedTarget.Write(events);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Forwards the array of log events to the <see cref="WrapperTargetBase.WrappedTarget"/> by calling the <see cref="Target.Write(LogEventInfo[])"/> method <see cref="RepeatCount"/> times.
        /// </summary>
        /// <param name="logEvents">The array of log events.</param>
        protected internal override void Write(LogEventInfo[] logEvents)
        {
            LogEventInfo[] newEvents = new LogEventInfo[logEvents.Length * RepeatCount];
            int            pos       = 0;

            for (int i = 0; i < logEvents.Length; ++i)
            {
                for (int j = 0; j < RepeatCount; ++j)
                {
                    newEvents[pos++] = logEvents[i];
                }
            }
            WrappedTarget.Write(newEvents);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Adds the specified log event to the buffer and flushes
 /// the buffer in case the buffer gets full.
 /// </summary>
 /// <param name="logEvent">The log event.</param>
 public override void Write(LogEventInfo logEvent)
 {
     lock (this)
     {
         WrappedTarget.PrecalculateVolatileLayouts(logEvent);
         int count = _buffer.Append(logEvent);
         if (count >= BufferSize)
         {
             LogEventInfo[] events = _buffer.GetEventsAndClear();
             WrappedTarget.Write(events);
         }
         else
         {
             if (FlushTimeout > 0 && _flushTimer != null)
             {
                 _flushTimer.Change(FlushTimeout, -1);
             }
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Forwards the call to the <see cref="WrapperTargetBase.WrappedTarget"/>.Write()
 /// and calls <see cref="Target.Flush()"/> on it.
 /// </summary>
 /// <param name="logEvent"></param>
 protected internal override void Write(LogEventInfo logEvent)
 {
     WrappedTarget.Write(logEvent);
     WrappedTarget.Flush();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Evaluates all filtering rules to find the first one that matches.
        /// The matching rule determines the filtering condition to be applied
        /// to all items in a buffer. If no condition matches, default filter
        /// is applied to the array of log events.
        /// </summary>
        /// <param name="logEvents">Array of log events to be post-filtered.</param>
        public override void Write(LogEventInfo[] logEvents)
        {
            ConditionExpression resultFilter = null;

            if (InternalLogger.IsTraceEnabled)
            {
                InternalLogger.Trace("Input: {0} events", logEvents.Length);
            }

            // evaluate all the rules to get the filtering condition

            for (int i = 0; i < logEvents.Length; ++i)
            {
                for (int j = 0; j < _rules.Count; ++j)
                {
                    object v = _rules[j].ExistsCondition.Evaluate(logEvents[i]);

                    if (v is bool && (bool)v)
                    {
                        if (InternalLogger.IsTraceEnabled)
                        {
                            InternalLogger.Trace("Rule matched: {0}", _rules[j].ExistsCondition);
                        }
                        resultFilter = _rules[j].FilterCondition;
                        break;
                    }
                }
                if (resultFilter != null)
                {
                    break;
                }
            }

            if (resultFilter == null)
            {
                resultFilter = _defaultFilter;
            }

            if (InternalLogger.IsTraceEnabled)
            {
                InternalLogger.Trace("Filter to apply: {0}", resultFilter);
            }

            // apply the condition to the buffer

            List <LogEventInfo> resultBuffer = new List <LogEventInfo>();

            for (int i = 0; i < logEvents.Length; ++i)
            {
                object v = resultFilter.Evaluate(logEvents[i]);
                if (v is bool && (bool)v)
                {
                    resultBuffer.Add(logEvents[i]);
                }
            }

            if (InternalLogger.IsTraceEnabled)
            {
                InternalLogger.Trace("After filtering: {0} events", resultBuffer.Count);
            }

            if (resultBuffer.Count > 0)
            {
                WrappedTarget.Write(resultBuffer.ToArray());
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Forwards the call to the <see cref="WrapperTargetBase.WrappedTarget"/>.Write()
 /// and calls <see cref="Target.Flush()"/> on it.
 /// </summary>
 /// <param name="logEvent"></param>
 public override void Write(LogEventInfo logEvent)
 {
     WrappedTarget.Write(logEvent);
     WrappedTarget.Flush();
 }