コード例 #1
0
        public void LogFailureTest()
        {
            EventEntry _lastEvent = null;

            using (SinkSubscription <ObservableEventListener> _subscription = SinkExtensions.CreateSink(x => _lastEvent = x))
            {
                Assert.IsNotNull(_subscription.Sink);
                _subscription.Sink.EnableEvents(SemanticEventSource.Log, EventLevel.LogAlways, Keywords.All);
                Assert.IsNull(_lastEvent);
                SemanticEventUser _logUser = new SemanticEventUser();
                _logUser.DataProcessing();
                Assert.IsNotNull(_lastEvent);

                //_lastEvent content
                Assert.AreEqual <int>(1, _lastEvent.EventId);
                Assert.AreEqual <Guid>(Guid.Empty, _lastEvent.ActivityId);
                Assert.AreEqual <string>("Application Failure: DataProcessing", _lastEvent.FormattedMessage, _lastEvent.FormattedMessage);
                Assert.AreEqual <string>("System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]", _lastEvent.Payload.ToString(), _lastEvent.Payload.ToString());
                Assert.AreEqual <int>(1, _lastEvent.Payload.Count);
                Assert.AreEqual <string>("DataProcessing", _lastEvent.Payload[0].ToString());
                Assert.AreEqual <string>("message", _lastEvent.Schema.Payload[0]);

                Assert.AreEqual <string>("Start", _lastEvent.Schema.OpcodeName);
                Assert.AreEqual <EventOpcode>(EventOpcode.Start, _lastEvent.Schema.Opcode);
                Assert.AreEqual <string>("Page", _lastEvent.Schema.TaskName);
                Assert.AreEqual <EventTask>(SemanticEventSource.Tasks.Page, _lastEvent.Schema.Task);
            }
        }
コード例 #2
0
        public void NamedEventSourceTest()
        {
            EventEntry _lastEvent = null;

            using (SinkSubscription <ObservableEventListener> _subscription = SinkExtensions.CreateSink(x => _lastEvent = x))
            {
                _subscription.Sink.EnableEvents("TPA-SemanticLogging", EventLevel.LogAlways, Keywords.All);
                Assert.IsNull(_lastEvent);
                SemanticEventUser _logUser = new SemanticEventUser();
                _logUser.DataProcessing();
                Assert.IsNotNull(_lastEvent);
                Assert.AreEqual <string>("Application Failure: DataProcessing", _lastEvent.FormattedMessage, _lastEvent.FormattedMessage);
            }
        }
コード例 #3
0
        public void FlatFileSinkTest()
        {
            string   _filePath = $"{nameof(FlatFileSinkTest)}.log";
            FileInfo _logFile  = new FileInfo(_filePath);

            if (_logFile.Exists)
            {
                _logFile.Delete();
            }
            SinkSubscription <FlatFileSink> m_FileSubscription = SinkExtensions.CreateSink(SemanticEventSource.Log, _filePath);

            _logFile.Refresh();
            Assert.IsTrue(_logFile.Exists);
            Assert.AreEqual <long>(0, _logFile.Length);
            SemanticEventUser _logUser = new SemanticEventUser();

            _logUser.DataProcessing();
            m_FileSubscription.Sink.FlushAsync();
            _logFile.Refresh();
            Assert.IsTrue(_logFile.Length > 100);
            m_FileSubscription.Dispose();
        }