public void LogActivityEndEvent_CreatesEvent(EventSourcesEventIds eventId, bool isHealthCheck)
        {
            TestEventListener listener = new TestEventListener();

            listener.EnableEvents(ActivityEventSource.Instance, EventLevel.Informational);

            string name     = "TestName";
            string subType  = "TestSubType";
            string metaData = "TestmetaData";
            Mock <IExecutionContext> contextMock = new Mock <IExecutionContext>();

            contextMock.Setup(c => c.ServiceName).Returns("TestService");

            ActivityEventSender logEventSource = new ActivityEventSender(
                ActivityEventSource.Instance,
                contextMock.Object,
                new NullLogger <ActivityEventSender>());

            string   expectedActivityId = string.Empty;
            Guid     correlationId      = Guid.NewGuid();
            Activity activity           = new Activity(name).Start();

            using (activity)
            {
                expectedActivityId = activity.Id ?? string.Empty;
                activity.SetSubType(subType);
                activity.SetMetadata(metaData);
                activity.SetUserHash("TestUserHash");
#pragma warning disable CS0618 // Type or member is obsolete
                activity.SetObsoleteCorrelationId(correlationId);
#pragma warning restore CS0618 // Type or member is obsolete
                if (isHealthCheck)
                {
                    activity.MarkAsHealthCheck();
                }
            }

            logEventSource.SendActivityMetric(activity);

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            eventInfo.AssertPayload("name", name);
            eventInfo.AssertPayload("subType", subType);
            eventInfo.AssertPayload("metadata", metaData);
            eventInfo.AssertPayload("activityId", expectedActivityId);
            eventInfo.AssertPayload("correlationId", correlationId.ToString());
        }
예제 #2
0
        public void LogTimedScopeEndEvent_CreatesEvent(EventSourcesEventIds eventId, bool isHealthCheck)
        {
            CustomEventListener listener = new CustomEventListener();

            listener.EnableEvents(TimedScopeEventSource.Instance, EventLevel.Informational);

            string name     = "TestName";
            string subType  = "TestSubType";
            string metaData = "TestmetaData";

            TimedScopeEventSender logEventSource = new TimedScopeEventSender(
                TimedScopeEventSource.Instance,
                new HostingEnvironment {
                ApplicationName = "TestApp"
            },
                new NullLogger <TimedScopeEventSender>());

            string   expectedActivityId = string.Empty;
            Activity activity           = new Activity(name);

            using (TimedScope scope = new TimedScope(activity, TimedScopeResult.Success).Start())
            {
                expectedActivityId = activity.Id;
                scope.SetSubType(subType);
                scope.SetMetadata(metaData);
                activity.SetUserHash("TestUserHash");
                if (isHealthCheck)
                {
                    activity.MarkAsHealthCheck();
                }
            }

            logEventSource.LogActivityStop(activity);

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            AssertPayload(eventInfo, "name", name);
            AssertPayload(eventInfo, "subType", subType);
            AssertPayload(eventInfo, "metadata", metaData);
            AssertPayload(eventInfo, "activityId", expectedActivityId);
        }
예제 #3
0
        public void LogMessage_CreatesProperEvents(EventLevel eventLevel, LogLevel logLevel, EventSourcesEventIds eventId)
        {
            TestEventListener listener = new TestEventListener();

            listener.EnableEvents(OmexLogEventSource.Instance, eventLevel);
            listener.EnableEvents(ServiceInitializationEventSource.Instance, EventLevel.Informational);

            string   message  = "Test message";
            string   category = "Test category";
            int      tagId    = 0xFFF9;
            Activity activity = new Activity("Test activity");

            activity.Start().Stop();             // start and stop activity to get correlation id

            Mock <IOptionsMonitor <OmexLoggingOptions> > mockOptions = new Mock <IOptionsMonitor <OmexLoggingOptions> >();

            mockOptions.Setup(m => m.CurrentValue).Returns(new OmexLoggingOptions());

            OmexLogEventSender logsSender = new OmexLogEventSender(
                OmexLogEventSource.Instance,
                new Mock <IExecutionContext>().Object,
                new EmptyServiceContext(),
                mockOptions.Object);

            logsSender.LogMessage(activity, category, logLevel, tagId, 0, message, new Exception("Not expected to be part of the event"));

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            eventInfo.AssertPayload("message", message);
            eventInfo.AssertPayload("category", category);
            eventInfo.AssertPayload("activityId", activity.Id ?? string.Empty);
            eventInfo.AssertPayload("tagId", "fff9");

            InitializationLogger.LogInitializationSucceed(category, message);


            eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)EventSourcesEventIds.GenericHostBuildSucceeded);

            eventInfo.AssertPayload("message", "Initialization successful for Test category, Test message");

            string newMessage = "New message";

            InitializationLogger.LogInitializationFail(category, new Exception("Not expected to be part of the event"), newMessage);

            eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)EventSourcesEventIds.GenericHostFailed);
            eventInfo.AssertPayload("message", newMessage);
        }
예제 #4
0
        public void LogMessage_CreatesProperEvents(EventLevel eventLevel, LogLevel logLevel, EventSourcesEventIds eventId)
        {
            CustomEventListener listener = new CustomEventListener();

            listener.EnableEvents(OmexLogEventSource.Instance, eventLevel);

            string   message  = "Test message";
            string   category = "Test category";
            int      tagId    = 0xFFF9;
            Activity activity = new Activity("Test activity");

            activity.Start().Stop();             // start and stop activity to get correlation id

            OmexLogEventSender logsSender = new OmexLogEventSender(
                OmexLogEventSource.Instance,
                new BasicMachineInformation(),
                new EmptyServiceContext(),
                Options.Create(new OmexLoggingOptions()));

            logsSender.LogMessage(activity, category, logLevel, tagId, 0, message);

            EventWrittenEventArgs eventInfo = listener.EventsInformation.Single(e => e.EventId == (int)eventId);

            AssertPayload(eventInfo, "message", message);
            AssertPayload(eventInfo, "category", category);
            AssertPayload(eventInfo, "activityId", activity.Id);
            AssertPayload(eventInfo, "tagId", "fff9");
        }