示例#1
0
        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;
        }
示例#2
0
        /// <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>());
        }