Beispiel #1
0
        public TraceWriterConfig(ILogWriterConfig logWriterConfig, SwitchSet switches = null)
        {
            Contract.Requires <ArgumentNullException>(logWriterConfig != null);

            _tracelogWriterConfig = logWriterConfig;
            _switches             = switches ?? new SwitchSet();
        }
Beispiel #2
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);
        }
Beispiel #3
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));
        }
Beispiel #4
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);
        }
Beispiel #5
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));
            }
        }
Beispiel #6
0
 public TraceWriterConfig(ILogWriter logWriter, SwitchSet switches = null)
     : this(new UseExistingLogWriterConfig(logWriter), switches)
 {
     Contract.Requires <ArgumentNullException>(logWriter != null);
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new <see cref="TraceWriterConfig" /> using all default values.
 /// If <see cref="LogWriterConfig" /> is not subsequently set, a <see cref="NoOpEntryWriter{TEntry}" /> will be
 /// used.
 /// </summary>
 public TraceWriterConfig()
 {
     _switches = new SwitchSet();
 }
Beispiel #8
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);
        }
Beispiel #9
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));
        }
Beispiel #10
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));
        }
Beispiel #11
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));
        }
Beispiel #12
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);
        }