예제 #1
0
 /// <summary>
 /// Creates a new <see cref="SetupLog" /> instance which records status entries according to
 /// <paramref name="statusTraceSwitch" />.
 /// </summary>
 /// <param name="statusTraceSwitch"></param>
 public SetupLog(ITraceSwitch statusTraceSwitch)
 {
     _tracers      = new Dictionary <string, Tracer>();
     _listEntries  = new List <TraceEntry>();
     _traceWriter  = new TraceWriter(statusTraceSwitch, this, null);
     _traceWriters = new[] { _traceWriter };
 }
예제 #2
0
        /// <summary>
        /// Creates a new <see cref="TraceWriter" /> using the specified <paramref name="traceSwitch" /> and
        /// <paramref name="traceEntryWriter" />.
        /// </summary>
        /// <param name="traceSwitch"></param>
        /// <param name="traceEntryWriter"></param>
        /// <param name="setupTracerFactory">
        /// The <see cref="ITracerFactory" /> to use to report exceptions.  If <c>null</c>,
        /// logging exceptions are not reported.
        /// </param>
        public TraceWriter(ITraceSwitch traceSwitch, IEntryWriter <TraceEntry> traceEntryWriter, ITracerFactory setupTracerFactory)
            : base(traceEntryWriter)
        {
            Contract.Requires <ArgumentNullException>(traceSwitch != null);

            _traceSwitch            = traceSwitch;
            _setupTracerFactory     = setupTracerFactory;
            _countWritingExceptions = 0;
        }
예제 #3
0
        public static TraceWriterConfig TraceToDebugger(this TraceManagerConfig traceManagerConfig,
                                                        string tracerName        = Tracer.All,
                                                        ITraceSwitch traceSwitch = null,
                                                        EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(tracerName != null);

            return(TraceToDebugger(traceManagerConfig, CreateSwitchSet(tracerName, traceSwitch), traceFormatter));
        }
예제 #4
0
        public static TraceWriterConfig TraceToList(this TraceManagerConfig traceManagerConfig,
                                                    IList <TraceEntry> list,
                                                    string tracerName        = Tracer.All,
                                                    ITraceSwitch traceSwitch = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(list != null);
            Contract.Requires <ArgumentNullException>(tracerName != null);

            return(TraceToList(traceManagerConfig, list, CreateSwitchSet(tracerName, traceSwitch)));
        }
        public static TraceWriterConfig TraceToTestOutput(this TraceManagerConfig traceManagerConfig,
                                                          ITestOutputHelper testOutput,
                                                          string tracerName        = Tracer.All,
                                                          ITraceSwitch traceSwitch = null,
                                                          EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(testOutput != null);
            Contract.Requires <ArgumentNullException>(tracerName != null);

            return(TraceManagerConfigFluentExtensions.TraceTo(traceManagerConfig, new TestOutputLogWriterConfig(testOutput), tracerName, traceSwitch, traceFormatter));
        }
예제 #6
0
 private static SwitchSet CreateSwitchSet(string rootTracerName, ITraceSwitch traceSwitch = null)
 {
     if (rootTracerName == null)
     {
         rootTracerName = Tracer.All;
     }
     if (traceSwitch == null)
     {
         traceSwitch = TraceManagerConfig.CreateDefaultTraceSwitch();
     }
     return(new SwitchSet()
     {
         { rootTracerName, traceSwitch }
     });
 }
예제 #7
0
        /// <summary>
        /// Creates a new <see cref="TraceManager" /> configured to use <paramref name="logWriterConfig" /> and
        /// <paramref name="traceSwitch" /> for all <see cref="Tracer" />s.
        /// </summary>
        /// <param name="logWriterConfig">The <see cref="ILogWriterConfig" /> to use to configure tracing.</param>
        /// <param name="traceSwitch">
        /// A <see cref="ITraceSwitch" /> to use for all <see cref="Tracer" />s.  If
        /// <c>null</c>, all <see cref="Tracer" /> calls of severity <see cref="TraceLevel.Info" /> or higher are written.
        /// </param>
        /// <param name="tracerNamePrefix">
        /// The <see cref="Tracer.Name" /> prefix to use.  Tracing will not occur if the
        /// <c>Tracer.Name</c> doesn't match this prefix.  By default, <see cref="Tracer.All" /> is used.
        /// </param>
        public TraceManager(ILogWriterConfig logWriterConfig, ITraceSwitch traceSwitch = null, string tracerNamePrefix = Tracer.All)
        {
            Contract.Requires <ArgumentNullException>(logWriterConfig != null);

            if (traceSwitch == null)
            {
                traceSwitch = TraceManagerConfig.CreateDefaultTraceSwitch();
            }

            // REVIEW: The need for this is messy, and we miss cases (eg multiple existing logwriters used) - perhaps each component manages its own messages?
            // If there's an existing LogWriter in the logwriter config, use its SetupLog, if any.
            ITracerFactory setupTracerFactory         = null;
            var            useExistingLogWriterConfig = logWriterConfig as UseExistingLogWriterConfig;

            if (useExistingLogWriterConfig != null)
            {
                var component = useExistingLogWriterConfig.LogWriter as ILogJamComponent;
                if (component != null)
                {
                    setupTracerFactory = component.SetupTracerFactory;
                }
            }

            _logManager = new LogManager(new LogManagerConfig(), setupTracerFactory);
            LinkDispose(_logManager); // b/c the LogManager is owned by this
            _traceConfig = new TraceManagerConfig(_logManager.Config)
            {
                Writers =
                {
                    new TraceWriterConfig(logWriterConfig)
                    {
                        Switches =
                        {
                            { tracerNamePrefix, traceSwitch }
                        }
                    }
                }
            };
        }
예제 #8
0
        public static TraceWriterConfig UseLogWriter(this TraceManagerConfig config, ILogWriter logWriter, string tracerName = Tracer.All, ITraceSwitch traceSwitch = null)
        {
            Contract.Requires <ArgumentNullException>(config != null);
            Contract.Requires <ArgumentNullException>(logWriter != null);
            Contract.Requires <ArgumentNullException>(tracerName != null);

            return(UseLogWriter(config, logWriter, CreateSwitchSet(tracerName, traceSwitch)));
        }
예제 #9
0
        public static TraceWriterConfig UseLogWriter(this TraceManagerConfig config, ILogWriter logWriter, Type type, ITraceSwitch traceSwitch = null)
        {
            Contract.Requires <ArgumentNullException>(config != null);
            Contract.Requires <ArgumentNullException>(logWriter != null);
            Contract.Requires <ArgumentNullException>(type != null);

            return(UseLogWriter(config, logWriter, CreateSwitchSet(type.GetCSharpName(), traceSwitch)));
        }
예제 #10
0
 /// <summary>
 /// Creates a new <see cref="TraceManager" /> configured to use <paramref name="logWriter" /> and
 /// <paramref name="traceSwitch" /> for all <see cref="Tracer" />s.
 /// </summary>
 /// <param name="logWriter">The <see cref="IEntryWriter{TEntry}" /> to use.</param>
 /// <param name="traceSwitch">
 /// A <see cref="ITraceSwitch" /> to use for all <see cref="Tracer" />s.  If
 /// <c>null</c>, all <see cref="Tracer" /> calls of severity <see cref="TraceLevel.Info" /> or higher are written.
 /// </param>
 /// <param name="tracerNamePrefix">
 /// The <see cref="Tracer.Name" /> prefix to use.  Tracing will not occur if the
 /// <c>Tracer.Name</c> doesn't match this prefix.  By default, <see cref="Tracer.All" /> is used.
 /// </param>
 public TraceManager(ILogWriter logWriter, ITraceSwitch traceSwitch = null, string tracerNamePrefix = Tracer.All)
     : this(new UseExistingLogWriterConfig(logWriter), traceSwitch, tracerNamePrefix)
 {
     Contract.Requires <ArgumentNullException>(logWriter != null);
 }