public void Should_send_an_sse_message_when_receiving_a_logging_event()
 {
     // given
     _target.Active = true;
     // when
     _target.Emit("INFO", "message");
     // then
     _channel.Received().Send(Arg.Is <ServerSentEvent>(evt => evt.ToString().Contains("message")), Arg.Any <CancellationToken>());
 }
 public void Should_send_an_sse_message_when_receiving_a_logging_event()
 {
     // given
     _target.Active = true;
     ApplyTargetConfiguration();
     // when
     LogManager.GetLogger(_target.Name, GetType()).Info("Everything's fine with NLog");
     // then
     _channel.Received().Send(Arg.Is <ServerSentEvent>(evt => evt.ToString().Contains("Everything's fine with NLog")), Arg.Any <CancellationToken>());
 }
Example #3
0
 public void Should_send_an_sse_message_when_receiving_a_logging_event()
 {
     // given
     _appender.Active = true;
     _appender.ActivateOptions();
     BasicConfigurator.Configure(_appender);
     // when
     LogManager.GetLogger(GetType()).Info("Everything's fine");
     // then
     _channel.Received().Send(Arg.Is <ServerSentEvent>(evt => evt.ToString().Contains("Everything's fine")), Arg.Any <CancellationToken>());
 }
        public void Should_send_an_sse_message_when_receiving_a_logging_event()
        {
            // given
            var channelFactory = Substitute.For<ChannelFactory>();
            _channel = Substitute.For<IEventChannel>();
            channelFactory.Create(Arg.Any<string>(), 8765, 1).Returns(_channel);
            var messageTemplateTextFormatter = new MessageTemplateTextFormatter(BrowserConsoleLoggerConfigurationExtensions.DefaultOutputTemplate, null);
            var sink = new BrowserConsoleSink(true, 8765, 1, messageTemplateTextFormatter, false, channelFactory);

            var logEvent = new LogEvent(
                new DateTimeOffset(new DateTime(2010, 10, 12)),
                LogEventLevel.Information,
                null,
                GenerateMessageTemplate("Everything's fine with Serilog"),
                new List<LogEventProperty>() { new LogEventProperty("test", new ScalarValue("value"))});

            // when
            sink.Emit(logEvent);

            // then
            _channel.Received().Send(Arg.Is<ServerSentEvent>(evt => evt.ToString().Contains("Everything's fine with Serilog")), Arg.Any<CancellationToken>());
        }
        public void Should_dispose_channel_on_shutdown()
        {
            // given
            var channelFactory = Substitute.For<ChannelFactory>();
            _channel = Substitute.For<IEventChannel>();
            channelFactory.Create(Arg.Any<string>(), 8765, 1).Returns(_channel);
            var sink = new BrowserConsoleSink(true, 8765, 1, null, false, channelFactory);

            //When
            sink.Dispose();

            // then
            _channel.Received().Dispose();
        }
        public void Should_send_a_multiline_sse_message_received_logging_event_for_an_exception()
        {
            // given
            var channelFactory = Substitute.For<ChannelFactory>();
            _channel = Substitute.For<IEventChannel>();
            channelFactory.Create(Arg.Any<string>(), 8765, 1).Returns(_channel);
            var messageTemplateTextFormatter = new MessageTemplateTextFormatter(BrowserConsoleLoggerConfigurationExtensions.DefaultOutputTemplate, null);
            var sink = new BrowserConsoleSink(true, 8765, 1, messageTemplateTextFormatter, false, channelFactory);

            var logEvent = new LogEvent(
                new DateTimeOffset(new DateTime(2010, 10, 12)),
                LogEventLevel.Fatal,
                new Exception("Message of the exception"), 
                GenerateMessageTemplate("Displaying of an exception"),
                new List<LogEventProperty>() { new LogEventProperty("test", new ScalarValue("value")) });

            // when
            sink.Emit(logEvent);

            // then
            var lineSeparator = new string[] { "\r\n" };
            _channel.Received().Send(
                Arg.Is<ServerSentEvent>(
                    evt => evt.ToString()
                        .Split(lineSeparator, StringSplitOptions.RemoveEmptyEntries)
                        .Skip(1)
                        .All(l => l.StartsWith("data:"))
                    ), Arg.Any<CancellationToken>());
        }