protected override void RecordMessageInternal(TraceEventMessage message)
        {
            Guid   activityId       = message.ActivityId;
            Guid   parentActivityId = message.ParentActivityId;
            string jsonPayload      = message.Payload;

            EventSourceOptions options = this.CreateOptions(message.Level, message.Keywords, message.Opcode);

            EventSource.SetCurrentThreadActivityId(activityId);

            if (string.IsNullOrEmpty(jsonPayload))
            {
                jsonPayload = "{}";
            }

            if (string.IsNullOrEmpty(this.ikey))
            {
                Payload payload = new Payload(message.Payload, this.enlistmentId, this.mountId);
                this.eventSource.Write(message.EventName, ref options, ref activityId, ref parentActivityId, ref payload);
            }
            else
            {
                PayloadWithIKey payload = new PayloadWithIKey(jsonPayload, this.enlistmentId, this.mountId, this.ikey);
                this.eventSource.Write(message.EventName, ref options, ref activityId, ref parentActivityId, ref payload);
            }
        }
示例#2
0
        public void EventListener_TryRecordMessage_MessageSentSuccessfully_ReturnsTrue()
        {
            TraceEventMessage message = new TraceEventMessage {
                Level = EventLevel.Error, Keywords = Keywords.None
            };
            TestEventListener listener = new TestEventListener(EventLevel.Informational, Keywords.Any);

            string actualErrorMessage;
            bool?  actualResult = listener.TryRecordMessage(message, out actualErrorMessage);

            Assert.IsTrue(actualResult);
            Assert.IsNull(actualErrorMessage);
        }
示例#3
0
        public void EventListener_TryRecordMessage_ListenerNotEnabledForMessage_ReturnsNull()
        {
            TraceEventMessage message = new TraceEventMessage {
                Level = EventLevel.Informational, Keywords = Keywords.None
            };
            TestEventListener listener = new TestEventListener(EventLevel.Critical, Keywords.Telemetry);

            string actualErrorMessage;
            bool?  actualResult = listener.TryRecordMessage(message, out actualErrorMessage);

            Assert.IsNull(actualResult);
            Assert.IsNull(actualErrorMessage);
        }
        public void Update_traceEvent_calls(string when)
        {
            using (var application = Platform.Win.NewApplication <ReactiveLoggerModule>()){
                application.AddModule <TestReactiveLoggerModule>();

                application.Title = nameof(Update_traceEvent_calls);

                var objectSpace = application.CreateObjectSpace();
                if (when == "DifferentLastEvent")
                {
                    objectSpace.CreateObject <TraceEvent>();
                    objectSpace.CommitChanges();
                }
                else if (when == "SameLastEvent")
                {
                    var traceEvent = objectSpace.CreateObject <TraceEvent>();
                    traceEvent.Source   = "source";
                    traceEvent.Location = "Location";
                    traceEvent.Method   = "Method";
                    traceEvent.Action   = "Action";
                    objectSpace.CommitChanges();
                }
                var message1 = new TraceEventMessage()
                {
                    Source = "source", Location = "Location", Method = "Method", Action = "Action"
                };
                var message2 = new TraceEventMessage()
                {
                    Source = "source", Location = "Location", Method = "Method", Action = "Action2"
                };

                var messages = new ITraceEvent[] { message1, message1, message2 };
                var save     = objectSpace.SaveTraceEvent(messages).SubscribeReplay();

                var testObserver = save.Test();
                testObserver.ItemCount.ShouldBe(2);
                if (when != "SameLastEvent")
                {
                    testObserver.Items[0].Called.ShouldBe(2);
                    testObserver.Items[1].Called.ShouldBe(1);
                }
                else
                {
                    testObserver.Items[0].Called.ShouldBe(3);
                    testObserver.Items[1].Called.ShouldBe(1);
                }
            }
        }
示例#5
0
        public void EventListener_TryRecordMessage_ExceptionThrownInternally_ReturnsFalseAndErrorMessage()
        {
            string expectedErrorMessage = "test error message";

            TraceEventMessage message = new TraceEventMessage {
                Level = EventLevel.Error, Keywords = Keywords.None
            };
            TestEventListener listener = new TestEventListener(EventLevel.Informational, Keywords.Any)
            {
                RecordMessageInternalCallback = _ => throw new Exception(expectedErrorMessage)
            };

            string actualErrorMessage;
            bool?  actualResult = listener.TryRecordMessage(message, out actualErrorMessage);

            Assert.IsFalse(actualResult);
            Assert.IsTrue(actualErrorMessage.Contains(expectedErrorMessage));
        }
示例#6
0
        public void EventListener_RecordMessage_ExceptionThrownInternally_RaisesFailureEventWithErrorMessage()
        {
            string expectedErrorMessage = $"test error message unique={Guid.NewGuid():N}";

            Mock <IEventListenerEventSink> eventSink = new Mock <IEventListenerEventSink>();

            TraceEventMessage message = new TraceEventMessage {
                Level = EventLevel.Error, Keywords = Keywords.None
            };
            TestEventListener listener = new TestEventListener(EventLevel.Informational, Keywords.Any, eventSink.Object)
            {
                RecordMessageInternalCallback = _ => throw new Exception(expectedErrorMessage)
            };

            listener.RecordMessage(message);

            eventSink.Verify(
                x => x.OnListenerFailure(listener, It.Is <string>(msg => msg.Contains(expectedErrorMessage))),
                times: Times.Once);
        }
示例#7
0
 protected override void RecordMessageInternal(TraceEventMessage message)
 {
     this.RecordMessageInternalCallback?.Invoke(message);
 }
示例#8
0
 protected override void RecordMessageInternal(TraceEventMessage message)
 {
     this.EventNamesRead.Add(message.EventName);
 }
示例#9
0
 public void OnTraceEvent(TraceEventMessage traceEvent)
 {
     TraceEventSubject.OnNext(traceEvent);
 }