/// <summary> /// Reports the start of an activity /// </summary> /// <param name="activity">The name of the activity</param> /// <param name="activityData">The data of the activity</param> /// <returns>A generated ID for the activity that was reported</returns> /// <typeparam name="T">the type of the activity data object</typeparam> public int ReportActivityStartIfAllowed <T>(string activity, T activityData) { if (this.isTelemetryAllowed) { EventSourceOptions telemetryOption = TelemetryEventSource.TelemetryOptions(); Interlocked.Increment(ref this.lastUsedActivityId); this.activitiesMap[this.lastUsedActivityId] = activity; this.eventSource.Write( string.Format("Activity{0}Started", activity), telemetryOption, new TelemetryEventData.ActivityEventData <T> { CorrelationId = this.correlationId, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, ActivityId = this.lastUsedActivityId, ActivityData = activityData }); return(this.lastUsedActivityId); } return(0); }
/// <summary> /// Reports the end of the session /// </summary> /// <param name="exitCode">Exit code of the program</param> public void ReportSessionEndIfAllowed(int exitCode) { if (this.isTelemetryAllowed) { EventSourceOptions telemetryOption = TelemetryEventSource.TelemetryOptions(); this.eventSource.Write( "SessionEnded", telemetryOption, new TelemetryEventData.SessionEndEventData { CorrelationId = this.correlationId, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, ExitCode = exitCode }); } }
/// <summary> /// Reports the start of a session /// </summary> public void ReportSessionStartIfAllowed() { if (this.isTelemetryAllowed) { EventSourceOptions telemetryOption = TelemetryEventSource.TelemetryOptions(); this.eventSource.Write( "SessionStarted", telemetryOption, new TelemetryEventData.SessionStartEventData { CorrelationId = this.correlationId, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, CommandLineArgs = EntryAssemblyArgs, Version = EntryAssemblyVersion, OsVersion = CurrentWindowsVersion }); } }
/// <summary> /// Reports the end of the specified activity /// </summary> /// <param name="activityId">The ID of the activity, generated by ReportActivityStartIfAllowed</param> /// <param name="activityData">The data of the activity</param> /// <typeparam name="T">the type of the activity data object</typeparam> public void ReportActivityEndIfAllowed <T>(int activityId, T activityData) { if (this.isTelemetryAllowed) { EventSourceOptions telemetryOption = TelemetryEventSource.TelemetryOptions(); string activity = this.activitiesMap[activityId]; this.eventSource.Write( string.Format("Activity{0}Ended", activity), telemetryOption, new TelemetryEventData.ActivityEventData <T> { CorrelationId = this.correlationId, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, ActivityId = activityId, ActivityData = activityData }); } }
/// <summary> /// Reports an exception that occurred during the execution of a activity, if an activity id is specified. /// </summary> /// <param name="exp">The exception that occurred</param> /// <param name="activityId">The ID of activity during which the exception occurred, generated by ReportActivityStartIfAllowed</param> public void ReportExceptionIfAllowed(Exception exp, int?activityId = null) { if (this.isTelemetryAllowed) { exp = exp.InnerException ?? exp; EventSourceOptions errorOption = TelemetryEventSource.TelemetryOptions(); errorOption.Level = EventLevel.Error; this.eventSource.Write( "ExceptionThrown", errorOption, new TelemetryEventData.ExceptionThrownEventData { CorrelationId = this.correlationId, Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond, ActivityId = activityId, Message = exp.Message, StackTrace = exp.StackTrace, }); } }