コード例 #1
0
 private void Send(Activity activity)
 {
     for (int i = 0; i < _senders.Count; i++)
     {
         IActivitySender sender = _senders[i];
         if (sender != null)
         {
             try
             {
                 sender.SendActivity(activity);
             }
             catch (Exception ex)
             {
                 LogInternalError(ex);
             }
         }
     }
 }
コード例 #2
0
        // Wrap event invocations inside a protected virtual method
        // to allow derived classes to override the event invocation behavior
        private static void OnRaiseActivityEvent(IActivitySender sender, ActivityEventArgs args)
        {
            //// Make a temporary copy of the event to avoid possibility of
            //// a race condition if the last subscriber unsubscribes
            //// immediately after the null check and before the event is raised.
            //EventHandler<ActivityEventArgs> handler = RaiseActivityEvent;

            //// Event will be null if there are no subscribers
            //if (handler != null)
            //{
            //    //// Format the string to send inside the CustomEventArgs parameter
            //    //e.Message += $" at {DateTime.Now}";

            //    // Use the () operator to raise the event.
            //    handler(sender, e);
            //}
            ActivityEvent?.Invoke(sender, args);
        }
コード例 #3
0
        private void LogInternalError(Exception exception, HashSet <IActivitySender> skipSenders)
        {
            if (exception == null)
            {
                return;
            }

            List <Exception> additionalExceptions = null;

            for (int i = 0; i < _senders.Count; i++)
            {
                IActivitySender sender = _senders[i];
                if (sender != null)
                {
                    try
                    {
                        if (skipSenders == null || false == skipSenders.Contains(sender))
                        {
                            sender.LogActivityInsightsError(exception);
                        }
                    }
                    catch (Exception ex)
                    {
                        skipSenders = skipSenders ?? new HashSet <IActivitySender>();
                        skipSenders.Add(sender);

                        additionalExceptions = additionalExceptions ?? new List <Exception>();
                        additionalExceptions.Add(ex);
                    }
                }
            }

            if (additionalExceptions != null)
            {
                for (int i = 0; i < additionalExceptions.Count; i++)
                {
                    LogInternalError(additionalExceptions[i], skipSenders);
                }
            }
        }
コード例 #4
0
        public static void Publish(IActivitySender sender, ActivityEventArgs.ActivityEnum activity, CurrentConn currentConnection)
        {
            ActivityEventArgs args = new ActivityEventArgs(activity, currentConnection);

            OnRaiseActivityEvent(sender, args);
        }