Esempio n. 1
0
 private static void Dispose(DiagnosticSourceStub diagnosticSource)
 {
     try
     {
         diagnosticSource.Dispose();
     }
     catch (Exception ex)
     {
         // If there was some business logic required to handle such errors, it would go here.
         ConsoleWrite.Exception(ex);
     }
 }
 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);
     }
 }
Esempio n. 3
0
        private static void CreateNewSource(ref DiagnosticSourceStub diagnosticSource)
        {
            try
            {
                DiagnosticSourceStub newDiagSrc = DiagnosticListening.CreateNewSource(DiagnosticEventsSpecification.StubbedSourceName);
                diagnosticSource = newDiagSrc;
            }
            catch (Exception ex)
            {
                diagnosticSource = DiagnosticSourceStub.NoOpStub;

                // If there was some business logic required to handle such errors, it would go here.
                ConsoleWrite.Exception(ex);
            }
        }
Esempio n. 4
0
 private static void WriteIfEnabled(DiagnosticSourceStub diagnosticSource, int currentIteration)
 {
     try
     {
         if (!diagnosticSource.IsNoOpStub && diagnosticSource.IsEnabled(DiagnosticEventsSpecification.StubbedSourceEventName))
         {
             diagnosticSource.Write(DiagnosticEventsSpecification.StubbedSourceEventName,
                                    new DiagnosticEventsSpecification.EventPayload(currentIteration, DiagnosticEventsSpecification.StubbedSourceName));
         }
     }
     catch (Exception ex)
     {
         // If there was some business logic required to handle such errors, it would go here.
         ConsoleWrite.Exception(ex);
     }
 }
 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);
     }
 }
 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);
     }
 }