public void CanLogHelloWorld_WithRawFormatter() { ConfigureTestLogger(new RawFormatter()); var arbitraryMessage = nameof(WhenLoggingViaTCP) + "CanLogHelloWorld_WithRawFormatter" + Guid.NewGuid(); _logger.Information(arbitraryMessage); var receivedData = ServerPoller.PollForReceivedData(_server); receivedData.Should().Contain($"Information: \"{arbitraryMessage}\""); }
public void CanLogHelloWorld_WithDefaultFormatter() { ConfigureTestLogger(); var arbitraryMessage = nameof(WhenLoggingViaUDP) + "CanLogHelloWorld_WithDefaultFormatter" + Guid.NewGuid(); _logger.Information(arbitraryMessage); var receivedData = ServerPoller.PollForReceivedData(_listener); receivedData.Should().Contain($"\"message\":\"{arbitraryMessage}\""); }
public void CanStillLogMessagesWithExceptions() { ConfigureTestLogger(new LogstashJsonFormatter()); var arbitraryMessage = nameof(JsonFormatter) + "CanStillLogMessagesWithExceptions" + Guid.NewGuid(); _logger.Information(new Exception("exploding"), arbitraryMessage); var receivedData = ServerPoller.PollForReceivedData(_server); receivedData.Should().Contain("\"exception\":\"System.Exception: exploding\"}"); }
public void CanLogWithProperties() { ConfigureTestLogger(); _logger.Information("TCP Hello {location}", "world"); var receivedData = ServerPoller.PollForReceivedData(_server); dynamic payload = JsonConvert.DeserializeObject <ExpandoObject>(receivedData); Assert.Equal("Information", payload.level); Assert.Equal("TCP Hello \"world\"", payload.message); Assert.Equal("world", payload.location); }
public void MustNotLogATrailingCommaWhenThereAreNoProperties() { ConfigureTestLogger(new LogstashJsonFormatter()); var arbitraryMessage = nameof(JsonFormatter) + "MustNotLogATrailingCommaWhenThereAreNoProperties" + Guid.NewGuid(); _logger.Information(arbitraryMessage); var receivedData = ServerPoller.PollForReceivedData(_server); var loggedData = receivedData?.TrimEnd('\n'); var logMessageWithTrailingComma = $"\"message\":\"{arbitraryMessage}\",}}"; loggedData.Should().NotEndWith(logMessageWithTrailingComma); }
public void CanLogHelloWorld_WithRawFormatter() { #pragma warning disable 618 // specifically testing the deprecated RawFormatter ConfigureTestLogger(new RawFormatter()); #pragma warning restore 618 var arbitraryMessage = nameof(WhenLoggingViaUDP) + "CanLogHelloWorld_WithRawFormatter" + Guid.NewGuid(); _logger.Information(arbitraryMessage); var receivedData = ServerPoller.PollForReceivedData(_listener); receivedData.Should().Contain($"Information: \"{arbitraryMessage}\""); }