/// <summary> /// This method implements the configuration for each <see cref="TraceSource"/>: /// this implements <see cref="ITraceSourceSelector"/>. /// This is implemented by invoking all added selector delegates; /// and configuring the argument based on the selection result. NOTICE that ANY /// <see cref="TraceSource"/> passed here will be configured; AND this does NOT /// maintain its own cache to the configured sources: if the configurations /// here change, ONLY sources added via <see cref="TraceSources"/> will be /// able to be re-configured. /// </summary> void ITraceSourceSelector.Select(SimpleTraceSource traceSource) { LogFileFactorySelection SelectAll() { LogFileFactorySelection selection = LogFileFactorySelection.Default; foreach (ILogFileFactorySelector selector in selectors) { selection |= selector.Select( traceSource.TraceSource, defaultTraceSourceSelection, selectedSwitchLevel); } return(selection); } lock (SyncLock) { if (!isInitialized) { return; } traceSource.TraceSource.Listeners.Remove(GetLogFileName()); LogFileFactorySelection result = SelectAll(); switch (result) { case LogFileFactorySelection.None: return; case LogFileFactorySelection.Default: result = defaultTraceSourceSelection; break; } if (result.HasFlag(LogFileFactorySelection.SwitchAndFilterLevels)) { SetSwitchLevel(traceSource); } if (result.HasFlag(LogFileFactorySelection.LogFileOutput) && (logFileListener != null)) { traceSource.TraceSource.Listeners.Add(logFileListener); } } void SetSwitchLevel(SimpleTraceSource simpleTraceSource) { #if DEBUG simpleTraceSource.TraceSource.Switch.Level = simpleTraceSource.TraceSource.Switch.Level.MostVerbose( SourceLevels.Information.MostVerbose(selectedSwitchLevel)); #else simpleTraceSource.TraceSource.Switch.Level = simpleTraceSource.TraceSource.Switch.Level.MostVerbose(selectedSwitchLevel); #endif } }
/// <summary> /// This method implements <see cref="ITraceSourceSelector"/>. /// </summary> void ITraceSourceSelector.Remove(SimpleTraceSource traceSource) => traceSource.TraceSource.Listeners.Remove(GetLogFileName());