public TelemetryMessage(IWorkContext context, TelemetryType telemetryType, string eventSourceName, string eventName, string?message, double value, IEventDimensions?eventDimensions = null) { context = context ?? throw new ArgumentNullException(nameof(context)); WorkContext = context; TelemetryType = telemetryType; EventSourceName = eventSourceName; EventName = eventName; Message = message; Value = value; EventDimensions = new EventDimensions(eventDimensions?.Select(x => x) ?? Standard.EventDimensions.Empty) + context.Dimensions; }
/// <summary> /// Create new event dimensions by merging two instances. "newOrOverrides" will take /// precedent of parent values /// </summary> /// <param name="source">source of dimension values</param> /// <param name="upserts">new or updates to dimension values</param> /// <returns>merged new event dimensions</returns> public static IEventDimensions WithUpserts(this IEventDimensions source, IEventDimensions upserts) { if (source == null) { return(null); } return(source .Select(x => new { Index = 2, Dim = x }) .Concat(upserts.Select(x => new { Index = 1, Dim = x })) .GroupBy(x => x.Dim.Key) .Select(x => x.OrderBy(y => y.Index).First()) .ToDictionary(x => x.Dim.Key, x => x.Dim.Value, StringComparer.InvariantCultureIgnoreCase) .AsTypeOrDefault <IEventDimensions>()); }