private IDisposable SubscribeToAllSources() { try { return(DiagnosticListening.SubscribeToAllSources(ObserverAdapter.OnAllHandlers( (DiagnosticListenerStub dl) => OnEventSourceObservered(dl), (Exception err) => ConsoleWrite.Exception(err), // Just for demo. Error handler is not actually necessary. () => ConsoleWrite.LineLine($"All-EventSources-Subscription Completed.")))); // Just for demo. Completion handler is not actually necessary. } catch (Exception ex) { // If there was some business logic required to handle such errors, it would go here. ConsoleWrite.Exception(ex); return(null); } }
public static bool SubscribeToAllSourcesSafe(IObserver <DiagnosticListenerStub> diagnosticSourcesObserver, out IDisposable result, out Exception error) { try { error = null; result = DiagnosticListening.SubscribeToAllSources(diagnosticSourcesObserver); return(true); } catch (Exception ex) { error = ex; if (s_isLogExceptionsEnabled) { Log.Error(s_logComponentMoniker, ex); } result = null; return(false); } }