protected override void Dispose(bool disposing) { try { if (!IsDisposed && disposing) { _listener?.Dispose(); } } finally { base.Dispose(disposing); } }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { Stop(); TraceListener?.Dispose(); } _disposed = true; }
/// <summary> /// Removes the tracelisteners from the specified trace sources. /// </summary> internal static void RemoveListenersByName( Collection <PSTraceSource> matchingSources, string[] listenerNames, bool fileListenersOnly) { Collection <WildcardPattern> listenerMatcher = SessionStateUtilities.CreateWildcardsFromStrings( listenerNames, WildcardOptions.IgnoreCase); // Loop through all the matching sources and remove the matching listeners foreach (PSTraceSource source in matchingSources) { // Get the indexes of the listeners that need to be removed. // This is done because we cannot remove the listeners while // we are enumerating them. for (int index = source.Listeners.Count - 1; index >= 0; --index) { TraceListener listenerToRemove = source.Listeners[index]; if (fileListenersOnly && !(listenerToRemove is TextWriterTraceListener)) { // Since we only want to remove file listeners, skip any that // aren't file listeners continue; } // Now match the names if (SessionStateUtilities.MatchesAnyWildcardPattern( listenerToRemove.Name, listenerMatcher, true)) { listenerToRemove.Flush(); listenerToRemove.Dispose(); source.Listeners.RemoveAt(index); } } } }
public void Dispose() { _listener?.Dispose(); }
public void Dispose() { Trace.Listeners.Remove(_output); _output.Dispose(); }
static void traceListenerClose(TraceListener traceListener) { traceListener.Close(); traceListener.Dispose(); traceListener = null; }
/////////////////////////////////////////////////////////////////////// private ReturnCode SetupTraceListeners( bool setup, bool console, bool strict, ref Result error ) { try { if (setup) { // // NOTE: Add our trace listener to the collections for // trace and debug output. // if (listener == null) { listener = Utility.NewDefaultTraceListener(console); /* IGNORED */ Utility.AddTraceListener(listener, false); /* IGNORED */ Utility.AddTraceListener(listener, true); return(ReturnCode.Ok); // NOTE: Success. } else if (strict) { error = "trace listeners already setup"; } else { return(ReturnCode.Ok); // NOTE: Fake success. } } else { // // NOTE: Remove and dispose our trace listeners now. // if (listener != null) { /* IGNORED */ Utility.RemoveTraceListener(listener, true); /* IGNORED */ Utility.RemoveTraceListener(listener, false); listener.Dispose(); listener = null; return(ReturnCode.Ok); // NOTE: Success. } else if (strict) { error = "trace listeners not setup"; } else { return(ReturnCode.Ok); // NOTE: Fake success. } } } catch (Exception e) { error = e; } return(ReturnCode.Error); }
/// <summary> /// 使用しているリソースを解放 /// </summary> public void Dispose() { listener.Close(); listener.Dispose(); }