/// <summary> /// Invokes the <see cref="TraceSources"/> factory method with a delegate /// that adds a verbose console trace listener to all sources. /// </summary> /// <returns>Dispose to reset the default factory.</returns> public static IDisposable TraceAllVerbose() { void Configure(SimpleTraceSource traceSource) { traceSource.TraceSource.TryAdd( new Diagnostics.ConsoleTraceListener { Filter = new EventTypeFilter(SourceLevels.All), }); traceSource.TraceSource.Switch.Level = SourceLevels.All; } void Remove(SimpleTraceSource traceSource) => traceSource.TraceSource.Listeners.Remove(Diagnostics.ConsoleTraceListener.DefaultName); DelegateTraceSourceSelector selector = new DelegateTraceSourceSelector(Configure, Remove); TraceSources.AddSelector(selector); TraceSources.For(typeof(TestHelper)) .Verbose("TraceSources are verbose."); void Dispose() => TraceSources.RemoveSelector(selector); return(DelegateDisposable.With(Dispose)); }
private void disposeResources() { disposeConfigFileWatcher(); traceAction($"{nameof(LogFileFactory)} Is Being Reset ..."); TraceSources.RemoveSelector(this); lock (SyncLock) { logFileListener?.Dispose(); logFileListener = null; } }
/// <summary> /// Removes a selector added in <see cref="AddSelector"/>. /// </summary> /// <param name="selector">Not null.</param> /// <exception cref="ArgumentNullException"></exception> public void RemoveSelector(ILogFileFactorySelector selector) { if (selector == null) { throw new ArgumentNullException(nameof(selector)); } lock (SyncLock) { if (!selectors.Remove(selector)) { return; } if (!isInitialized || !addToTraceSources || isInitializing) { return; } } TraceSources.RemoveSelector(this); TraceSources.AddSelector(this); }