internal static void RaiseEvent(IActivityScope activityScope, ActivityEventArgs args)
        {
            EventHandler <ActivityEventArgs> onActivityEvent = ActivityContext.OnActivityEvent;

            if (onActivityEvent != null && activityScope != null)
            {
                Guid activityId = activityScope.ActivityId;
                ExTraceGlobals.ActivityContextTracer.TraceDebug <ActivityEventType, Guid, int>(0L, "ActivityContext.RaiseEvent - raising event {0} for ActivityId {1}, and callback {2}.", args.ActivityEventType, activityId, onActivityEvent.GetHashCode());
                onActivityEvent(activityScope, args);
            }
        }
        private static ActivityScope AddActivityScope(ActivityContextState activityContextState, object userState, ActivityType activityType, ActivityEventArgs eventArgs, LocalizedString exceptionString)
        {
            bool          flag          = false;
            bool          flag2         = false;
            ActivityScope activityScope = null;

            if (ActivityContext.IsStarted)
            {
                try
                {
                    throw new ActivityContextException(exceptionString);
                }
                catch (ActivityContextException)
                {
                    flag2 = true;
                }
                if (SingleContext.Singleton.CheckId())
                {
                    ActivityScopeImpl activityScopeImpl = (ActivityScopeImpl)ActivityContext.GetCurrentActivityScope();
                    if (activityScopeImpl != null)
                    {
                        return(new ActivityScope(activityScopeImpl));
                    }
                }
            }
            if (SingleContext.Singleton.LocalId != null && !flag2)
            {
                try
                {
                    throw new ActivityContextException(DiagnosticsResources.ExceptionActivityContextMustBeCleared(DebugContext.GetDebugInfo()));
                }
                catch (ActivityContextException)
                {
                }
            }
            ActivityScope result;

            try
            {
                activityScope              = ActivityScopeImpl.AddActivityScope(activityContextState);
                activityScope.UserState    = userState;
                activityScope.ActivityType = activityType;
                ActivityContext.RaiseEvent(activityScope.ActivityScopeImpl, eventArgs);
                ExTraceGlobals.ActivityContextTracer.TraceDebug <Guid, bool>((long)activityScope.LocalId.GetHashCode(), "ActivityContext.AddActivityScope - ActivityId {0}, (activityContextState != null) = {1}", activityScope.ActivityId, activityContextState != null);
                flag   = true;
                result = activityScope;
            }
            finally
            {
                if (!flag)
                {
                    if (activityScope != null)
                    {
                        activityScope.Dispose();
                    }
                    ActivityContext.ClearThreadScope();
                }
            }
            return(result);
        }
 internal void OnActivityContextEvent(object sender, ActivityEventArgs args)
 {
     this.logger.LogActivityEvent((IActivityScope)sender, args.ActivityEventType);
 }