示例#1
0
        private static int GetAttributeValue(XElement configuration, string attributeName, int defaultValue)
        {
            var attribute = configuration.Attributes().FirstOrDefault(a => a.Name == attributeName);

            if (attribute == null)
            {
                return(defaultValue);
            }
            int temp;

            if (int.TryParse(attribute.Value, out temp) && temp > 0)
            {
                return(temp);
            }
            RawLogger.LogWarning(ErrorCodes.Framework.ListenerInvalidConfiguration,
                                 string.Format(CultureInfo.CurrentCulture, InternalMessages.FrameworkListenerInvalidAttributeBackToDefault,
                                               attributeName, defaultValue));
            return(defaultValue);
        }
示例#2
0
        /// <summary>
        ///     Sends up to MaxTraceEventbyPacket trace events to the writing delegate.
        /// </summary>
        /// <returns>True if there is still traces to emit, false otherwise.</returns>
        private bool SendTraces()
        {
            if (_writeEventsToStore == null || _tracesQueue.IsEmpty)
            {
                return(false);
            }

            int traceEventsCount             = Math.Min(_maxTraceEventsByCall, _tracesQueue.Count);
            List <TraceEventData> eventsList = new List <TraceEventData>();

            for (int i = 0; i < traceEventsCount; i++)
            {
                TraceEventData item;
                if (_tracesQueue.TryDequeue(out item))
                {
                    eventsList.Add(item);
                }
                else
                {
                    break;
                }
            }
            if (eventsList.Count <= 0)
            {
                return(false);
            }
            try
            {
                _writeEventsToStore(eventsList);
            }
            catch (Exception exception)
            {
                // 1. Because the TraceListener is written to manage Exception we do not want to rethrow it,
                //    once again to avoid infinite loop: but we log the error in the event-log to trace the problem.
                // 2. We also decrement a counter to avoid filling the event-log.
                if (--_remainingErrorsToLog > 0)
                {
                    RawLogger.LogWarning(ErrorCodes.Framework.ListenerLoggingError,
                                         string.Format(CultureInfo.CurrentCulture, InternalMessages.FrameworkListenerLoggingError, exception));
                }
            }
            return(true);
        }
示例#3
0
        /// <summary>
        ///     Trace the specified data.
        /// </summary>
        /// <param name="eventCache">The specified cache object.</param>
        /// <param name="source">The name of the source</param>
        /// <param name="eventType">The specified System.Dagnostics trace event type.</param>
        /// <param name="id">The specified event id.</param>
        /// <param name="data">The custom data object that will hold our <see cref="TraceEventData" /> object.</param>
        public override void TraceData(TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data, null))
            {
                return;
            }

            if (_tracesQueue.Count >= _maxQueueSize)
            {
                // No connection string
                if (--_remainingErrorsToLog > 0)
                {
                    RawLogger.LogWarning(ErrorCodes.Framework.ListenerFlooded, InternalMessages.FrameworkListenerFlooded);
                }
                return;
            }

            _tracesQueue.Enqueue(data as TraceEventData);
        }