/// <summary>
 /// Adds the specified <see cref="TraceListener"/> to the log source to work asynchronously.
 /// </summary>
 /// <param name="logSource">The log source to add the trace listener to.</param>
 /// <param name="traceListener">The trace listener to add.</param>
 /// <param name="bufferSize">The size of the buffer for asynchronous requests.</param>
 /// <param name="maxDegreeOfParallelism">The max degree of parallelism for thread safe listeners. Specify <see langword="null"/> to use the current core count.</param>
 /// <param name="disposeTimeout">The timeout for waiting to complete buffered requests when disposing. When <see langword="null" /> the default of <see cref="System.Threading.Timeout.InfiniteTimeSpan" /> is used.</param>
 public static void AddAsynchronousTraceListener(
     this LogSourceData logSource,
     TraceListener traceListener,
     int?bufferSize             = AsynchronousTraceListenerWrapper.DefaultBufferSize,
     int?maxDegreeOfParallelism = null,
     TimeSpan?disposeTimeout    = null)
 {
     logSource.AddTraceListener(BuildAsynchronousWrapper(traceListener, bufferSize, maxDegreeOfParallelism, disposeTimeout));
 }
        /// <summary>
        /// Adds a new log source with the specified name, level, and trace listeners, and optionally enables auto-flush.
        /// </summary>
        /// <param name="name">The name of the log source.</param>
        /// <param name="level">The filtering level of the log source.</param>
        /// <param name="autoFlush"><see langword="true"/> to enable auto-flush; otherwise, <see langword="false"/>.</param>
        /// <param name="traceListeners">One or more <see cref="TraceListener"/> objects.</param>
        /// <returns>A new <see cref="LogSourceData"/> instance.</returns>
        public LogSourceData AddLogSource(string name, SourceLevels level, bool autoFlush, params TraceListener[] traceListeners)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (traceListeners == null)
            {
                throw new ArgumentNullException("traceListeners");
            }

            var sourceData = new LogSourceData()
            {
                AutoFlush = autoFlush,
                Name      = name,
                Level     = level
            };

            foreach (var traceListener in traceListeners)
            {
                if (traceListener == null)
                {
                    throw new ArgumentNullException("traceListeners");
                }

                sourceData.Listeners.Add(traceListener);
            }

            this.LogSources.Add(sourceData);

            // Make it default if necessary
            if (string.IsNullOrWhiteSpace(this.DefaultSource))
            {
                this.DefaultSource = name;
            }

            return(sourceData);
        }
 /// <summary>
 /// Adds the specified <see cref="TraceListener"/> to the log source.
 /// </summary>
 /// <param name="logSource">The log source to add the trace listener to.</param>
 /// <param name="traceListener">The trace listener to add.</param>
 public static void AddTraceListener(this LogSourceData logSource, TraceListener traceListener)
 {
     logSource.Listeners.Add(traceListener);
 }
Esempio n. 4
0
        /// <summary>
        /// Adds a new log source with the specified name, level, and trace listeners, and optionally enables auto-flush.
        /// </summary>
        /// <param name="name">The name of the log source.</param>
        /// <param name="level">The filtering level of the log source.</param>
        /// <param name="autoFlush"><see langword="true"/> to enable auto-flush; otherwise, <see langword="false"/>.</param>
        /// <param name="traceListeners">One or more <see cref="TraceListener"/> objects.</param>
        /// <returns>A new <see cref="LogSourceData"/> instance.</returns>
        public LogSourceData AddLogSource(string name, SourceLevels level, bool autoFlush, params TraceListener[] traceListeners)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (traceListeners == null)
            {
                throw new ArgumentNullException("traceListeners");
            }

            var sourceData = new LogSourceData()
            {
                AutoFlush = autoFlush,
                Name = name,
                Level = level
            };

            foreach (var traceListener in traceListeners)
            {
                if (traceListener == null)
                {
                    throw new ArgumentNullException("traceListeners");
                }

                sourceData.Listeners.Add(traceListener);
            }

            this.LogSources.Add(sourceData);

            // Make it default if necessary
            if (string.IsNullOrWhiteSpace(this.DefaultSource))
                this.DefaultSource = name;

            return sourceData;
        }