Ejemplo n.º 1
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)));
        }
Ejemplo n.º 2
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)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Enables sending trace messages to all configured log writers.
        /// </summary>
        /// <param name="traceManager"></param>
        /// <param name="switches"></param>
        /// <param name="traceFormatter"></param>
        /// <returns></returns>
        public static void TraceToAllLogWriters(this TraceManagerConfig config,
                                                SwitchSet switches = null,
                                                EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(config != null);

            TraceTo(config, config.LogManagerConfig.Writers, switches, traceFormatter);
        }
Ejemplo n.º 4
0
        public static TraceWriterConfig TraceToDebugger(this TraceManagerConfig traceManagerConfig, SwitchSet switchSet, EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            DebuggerLogWriterConfig debuggerLogWriterConfig = traceManagerConfig.LogManagerConfig.UseDebugger();

            return(TraceTo(traceManagerConfig, debuggerLogWriterConfig, switchSet, traceFormatter));
        }
Ejemplo n.º 5
0
        public static TraceWriterConfig TraceToConsole(this TraceManagerConfig traceManagerConfig, SwitchSet switchSet, EntryFormatter <TraceEntry> traceFormatter = null, bool colorize = true)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            ConsoleLogWriterConfig consoleLogWriterConfig = traceManagerConfig.LogManagerConfig.UseConsole(colorize);

            return(TraceTo(traceManagerConfig, consoleLogWriterConfig, switchSet, traceFormatter));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Trace to the logwriter configured by <paramref name="logWriterConfig" />.
        /// </summary>
        /// <param name="traceManagerConfig"></param>
        /// <param name="logWriterConfig"></param>
        /// <param name="switchSet"></param>
        /// <returns></returns>
        public static TraceWriterConfig TraceTo(this TraceManagerConfig traceManagerConfig, LogWriterConfig logWriterConfig, SwitchSet switchSet)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(logWriterConfig != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            var traceWriterConfig = new TraceWriterConfig(logWriterConfig, switchSet);

            traceManagerConfig.Writers.Add(traceWriterConfig);
            return(traceWriterConfig);
        }
Ejemplo n.º 8
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)));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Use an existing <paramref name="logWriter" /> along with the specified <paramref name="switchSet" />.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="logWriter"></param>
        /// <param name="switchSet"></param>
        public static TraceWriterConfig UseLogWriter(this TraceManagerConfig config, ILogWriter logWriter, SwitchSet switchSet)
        {
            Contract.Requires <ArgumentNullException>(config != null);
            Contract.Requires <ArgumentNullException>(logWriter != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            var traceWriterConfig = new TraceWriterConfig(logWriter, switchSet);

            config.Writers.Add(traceWriterConfig);
            return(traceWriterConfig);
        }
Ejemplo n.º 10
0
        public static TraceWriterConfig TraceTo(this TraceManagerConfig traceManagerConfig,
                                                Func <TextWriter> createTextWriterFunc,
                                                SwitchSet switchSet,
                                                EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(createTextWriterFunc != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            return(TraceTo(traceManagerConfig, new TextWriterLogWriterConfig(createTextWriterFunc), switchSet, traceFormatter));
        }
Ejemplo n.º 11
0
        public static TraceWriterConfig TraceToList(this TraceManagerConfig traceManagerConfig, IList <TraceEntry> list, SwitchSet switchSet)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(list != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            var listLogWriterConfig = new ListLogWriterConfig <TraceEntry>()
            {
                List = list
            };

            return(TraceTo(traceManagerConfig, listLogWriterConfig, switchSet));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Trace to the text logwriter configured by <paramref name="textLogWriterConfig" />.
        /// </summary>
        /// <param name="traceManagerConfig"></param>
        /// <param name="textLogWriterConfig"></param>
        /// <param name="switchSet"></param>
        /// <param name="traceFormatter"></param>
        /// <returns></returns>
        public static TraceWriterConfig TraceTo(this TraceManagerConfig traceManagerConfig,
                                                TextLogWriterConfig textLogWriterConfig,
                                                SwitchSet switchSet,
                                                EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(textLogWriterConfig != null);
            Contract.Requires <ArgumentNullException>(switchSet != null);

            textLogWriterConfig.Format(traceFormatter);
            var traceWriterConfig = new TraceWriterConfig(textLogWriterConfig, switchSet);

            traceManagerConfig.Writers.Add(traceWriterConfig);
            return(traceWriterConfig);
        }
Ejemplo n.º 13
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 }
     });
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Enables sending trace messages to all specified <paramref name="logWriterConfigs" />.  This method can be called
        /// multiple times
        /// to specify different switch settings for different logWriters.
        /// </summary>
        /// <param name="traceManagerConfig"></param>
        /// <param name="logWriterConfigs"></param>
        /// <param name="switches"></param>
        /// <param name="traceFormatter"></param>
        /// <returns></returns>
        public static void TraceTo(this TraceManagerConfig traceManagerConfig,
                                   IEnumerable <ILogWriterConfig> logWriterConfigs,
                                   SwitchSet switches = null,
                                   EntryFormatter <TraceEntry> traceFormatter = null)
        {
            Contract.Requires <ArgumentNullException>(traceManagerConfig != null);
            Contract.Requires <ArgumentNullException>(logWriterConfigs != null);

            if (switches == null)
            {
                switches = TraceManagerConfig.CreateDefaultSwitchSet();
            }

            logWriterConfigs.FormatAll(traceFormatter);
            foreach (var logWriterConfig in logWriterConfigs)
            {
                traceManagerConfig.Writers.Add(new TraceWriterConfig(logWriterConfig, switches));
            }
        }