示例#1
0
        /// <summary>
        /// Configuration method called by <see cref="TraceManager" /> after <see cref="TraceManager.GetTracer" /> is called,
        /// or when the configuration is changed for this <c>Tracer</c>.
        /// </summary>
        /// <param name="traceWriters">
        /// The array of 0 or more <see cref="TraceWriter" />s used by this <see cref="Tracer" /> to
        /// write trace messages.
        /// </param>
        /// <returns>
        /// The previous <see cref="TraceWriter" />s, or <c>null</c> if no <see cref="TraceWriter" />s were previously
        /// configured..
        /// </returns>
        internal TraceWriter[] Configure(TraceWriter[] traceWriters)
        {
            Contract.Requires <ArgumentNullException>(traceWriters != null);
            Contract.Requires <ArgumentException>(traceWriters.All(writer => writer != null));

            ITraceWriter newWriter;

            if (traceWriters.Length == 0)
            {
                newWriter = new NoOpTraceWriter();
            }
            else if (traceWriters.Length == 1)
            {
                newWriter = traceWriters[0];
            }
            else
            {
                newWriter = new FanOutTraceWriter(traceWriters);
            }

            TraceWriter[] previousTraceWriters = _writer == null ? null : _writer.ToTraceWriterArray();

            // REVIEW: This is a lockless set - ok?
            // The expectation is that these values are set infrequently, and it doesn't matter if the switch changes before the traceLogWriter does
            _writer = newWriter;

            return(previousTraceWriters);
        }
示例#2
0
        protected override void InternalStop()
        {
            lock (this)
            {
                _activeTraceEntryWriters.Clear();

                // Set all Tracers to write to a NoOpTraceWriter
                var noopTraceWriter = new NoOpTraceWriter();
                ForEachTracer(tracer => tracer.Writer = noopTraceWriter);
            }
        }