Esempio n. 1
0
        public static EventTelemetry ToEventTelemetry(this EventId evt, string message, params object[] args)
        {
            var retVal = new EventTelemetry(evt.Name ?? throw new ArgumentNullException(nameof(evt), @"Event name cannot be null"));

            retVal.Properties.Add($@"{EventPrefix}.EventId", evt.Id.ToString(CultureInfo.InvariantCulture));
            retVal.Properties.Add($@"{EventPrefix}.EventName", evt.Name.ToString(CultureInfo.InvariantCulture));
            retVal.Properties.Add($@"{EventPrefix}.Severity", evt.GetLevelName());
            retVal.Properties.Add($@"{EventPrefix}.Subsystem", evt.GetSubsystemName());

            if (!string.IsNullOrWhiteSpace(message))
            {
                retVal.Properties.Add($@"{EventPrefix}.Message", string.Format(CultureInfo.InvariantCulture, message, args));
            }

            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Check that both EventHelper.CreateEventId and the EventId constructor proper create the same thing
        /// </summary>
        public void EventHelperShouldCreateExactSameEventViaAnyConstructor()
        {
            var subSystem = LogEventIds.LogEventIdSubsystem.Encode;
            var level     = LogEventIds.LogEventIdLevel.Debug;
            var index     = 22;
            var msgText   = "Some interesting text";

            int computedId   = ((int)level * 100000) + ((int)subSystem * 1000) + index;
            int ehComputedId = LogEventIds.GenerateId(level, subSystem, index);

            var ev1 = new EventId(computedId, msgText);
            var ev2 = EventHelpers.CreateEventId(subSystem, level, index, msgText);

            ehComputedId.ShouldBe(computedId, "LogEventIds.GenerateId != computed ID");
            ev1.GetLevelName().ShouldBe(ev2.GetLevelName());
            ev1.GetSubsystemName().ShouldBe(ev2.GetSubsystemName());
            ev1.Id.ShouldBe(ev2.Id);
            ev1.Name.ShouldBe(ev2.Name);
            ev1.GetHashCode().ShouldBe(ev2.GetHashCode());
        }