/// <summary> /// Maps a <see cref="EventWrittenEventArgs"/> to a <see cref="TelemetryEvent"/>. /// </summary> /// <param name="source">An event to map.</param> /// <param name="sessionName">A session name to add to the destination object.</param> /// <returns>A instance of <see cref="TelemetryEvent"/>.</returns> public static TelemetryEvent Map(this EventWrittenEventArgs source, string sessionName) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (string.IsNullOrWhiteSpace(sessionName)) { throw new ArgumentNullException(nameof(sessionName)); } TelemetryEvent destination = new TelemetryEvent { ApplicationId = source.GetApplicationId(), AttachmentId = source.GetAttachmentId(), Channel = (int)source.Channel, Id = source.EventId, Level = source.Level, Message = source.GetFormattedMessage(), Name = source.EventName, Payloads = source.GetPayloads(), ProcessId = 0, ProcessName = null, ProviderId = source.EventSource.Guid, ProviderName = source.EventSource.Name, OpcodeId = (int)source.Opcode, OpcodeName = source.Opcode.ToString(), ActivityId = source.GetActivityId(), RelatedActivityId = source.RelatedActivityId, Keywords = source.Keywords, SessionName = sessionName, TaskId = (int)source.Task, TaskName = source.Task.ToString(), ThreadId = 0, Timestamp = DateTime.UtcNow.Ticks, UserId = source.GetUserId(), Version = source.Version }; return(destination); }