private string GetName(DiagnosticListenerStub diagnosticListener) { try { return(diagnosticListener.Name); } catch (Exception ex) { // If there was some business logic required to handle such errors, it would go here. ConsoleWrite.Exception(ex); return(null); } }
private void OnEventSourceObservered(DiagnosticListenerStub diagnosticListener) { string diagnosticListenerName = GetName(diagnosticListener); if (diagnosticListenerName == null) { return; } if (diagnosticListenerName.Equals(DiagnosticEventsSpecification.DirectSourceName, StringComparison.Ordinal)) { SubscribeToEvents(diagnosticListener, DiagnosticEventsSpecification.DirectSourceEventName, OnEventObservered); } if (diagnosticListenerName.Equals(DiagnosticEventsSpecification.StubbedSourceName, StringComparison.Ordinal)) { SubscribeToEvents(diagnosticListener, DiagnosticEventsSpecification.StubbedSourceEventName, OnEventObservered); } }
public static bool GetNameSafe(this DiagnosticListenerStub diagnosticListener, out string result, out Exception error) { try { error = null; result = diagnosticListener.Name; return(true); } catch (Exception ex) { error = ex; if (s_isLogExceptionsEnabled) { Log.Error(s_logComponentMoniker, ex); } result = null; return(false); } }
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); } }