private IDisposable SubscribeToEvents(DiagnosticListenerStub diagnosticListener, string eventNamePrefix, Action <KeyValuePair <string, object> > eventHandler) { try { if (eventNamePrefix == null) { return(diagnosticListener.SubscribeToEvents(ObserverAdapter.OnNextHandler(eventHandler), null)); } else { return(diagnosticListener.SubscribeToEvents( ObserverAdapter.OnNextHandler(eventHandler), (string eventName, object _, object __) => (eventName != null) && eventName.StartsWith(eventNamePrefix, StringComparison.Ordinal))); } } 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 SubscribeToEventsSafe(this DiagnosticListenerStub diagnosticListener, IObserver <KeyValuePair <string, object> > eventObserver, Func <string, object, object, bool> isEventEnabledFilter, out IDisposable result, out Exception error) { try { error = null; result = diagnosticListener.SubscribeToEvents(eventObserver, isEventEnabledFilter); return(true); } catch (Exception ex) { error = ex; if (s_isLogExceptionsEnabled) { Log.Error(s_logComponentMoniker, ex); } result = null; return(false); } }