示例#1
0
        private EventSourceActivity Start <T>(string?eventName, ref EventSourceOptions options, ref T data)
        {
            if (this.state != State.Started)
            {
                throw new InvalidOperationException();
            }

            // If the source is not on at all, then we don't need to do anything and we can simply return ourselves.
            if (!this.eventSource.IsEnabled())
            {
                return(this);
            }

            var newActivity = new EventSourceActivity(eventSource);

            if (!this.eventSource.IsEnabled(options.Level, options.Keywords))
            {
                // newActivity.relatedActivityId = this.Id;
                Guid relatedActivityId = this.Id;
                newActivity.activityId              = Guid.NewGuid();
                newActivity.startStopOptions        = options;
                newActivity.eventName               = eventName;
                newActivity.startStopOptions.Opcode = EventOpcode.Start;
                this.eventSource.Write(eventName, ref newActivity.startStopOptions, ref newActivity.activityId, ref relatedActivityId, ref data);
            }
            else
            {
                // If we are not active, we don't set the eventName, which basically also turns off the Stop event as well.
                newActivity.activityId = this.Id;
            }

            return(newActivity);
        }
示例#2
0
        private EventSourceActivity Start <T>(string eventName, ref EventSourceOptions options, ref T data)
        {
            if (this.state != EventSourceActivity.State.Started)
            {
                throw new InvalidOperationException();
            }
            if (!this.eventSource.IsEnabled())
            {
                return(this);
            }
            EventSourceActivity eventSourceActivity = new EventSourceActivity(this.eventSource);

            if (!this.eventSource.IsEnabled(options.Level, options.Keywords))
            {
                Guid id = this.Id;
                eventSourceActivity.activityId              = Guid.NewGuid();
                eventSourceActivity.startStopOptions        = options;
                eventSourceActivity.eventName               = eventName;
                eventSourceActivity.startStopOptions.Opcode = EventOpcode.Start;
                this.eventSource.Write <T>(eventName, ref eventSourceActivity.startStopOptions, ref eventSourceActivity.activityId, ref id, ref data);
            }
            else
            {
                eventSourceActivity.activityId = this.Id;
            }
            return(eventSourceActivity);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the EventSourceActivity class that
        /// is attached to the specified parent activity.
        /// The activity is created in the Initialized state. Call Start() to
        /// write the activity's Start event.
        /// </summary>
        /// <param name="parentActivity">
        /// The parent activity. Activity events will be written
        /// to the event source attached to this activity.
        /// </param>
        /// <param name="startStopOptions">
        /// The options to use for the start and stop events of the activity.
        /// Note that the Opcode property will be ignored.
        /// </param>
        internal EventSourceActivity(EventSourceActivity parentActivity, EventSourceOptions startStopOptions)
        {
            Contract.Requires <ArgumentNullException>(parentActivity != null, nameof(parentActivity));

            _eventSource      = parentActivity.EventSource;
            _startStopOptions = startStopOptions;
            _parentId         = parentActivity.Id;
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the EventSourceActivity class that
 /// is attached to the specified parent activity.
 /// The activity is created in the Initialized state. Call Start() to
 /// write the activity's Start event.
 /// </summary>
 /// <param name="parentActivity">
 /// The parent activity. Activity events will be written
 /// to the event source attached to this activity.
 /// </param>
 internal EventSourceActivity(EventSourceActivity parentActivity)
     : this(parentActivity, new EventSourceOptions())
 {
 }