diff --git a/src/Serilog.Sinks.Loki/LokiBatchFormatter.cs b/src/Serilog.Sinks.Loki/LokiBatchFormatter.cs index d8b3b09..1a1e4a4 100644 --- a/src/Serilog.Sinks.Loki/LokiBatchFormatter.cs +++ b/src/Serilog.Sinks.Loki/LokiBatchFormatter.cs @@ -86,10 +86,13 @@ public void Format(IEnumerable logEvents, TextWriter output) private static string GetLevel(LogEventLevel level) { - if (level == LogEventLevel.Information) - return "info"; - - return level.ToString().ToLower(); + switch (level) + { + case LogEventLevel.Verbose: return "trace"; + case LogEventLevel.Information: return "info"; + case LogEventLevel.Fatal: return "critical"; + default: return level.ToString().ToLower(); + } } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Loki.Tests/Labels/LogLevelLabelTests.cs b/test/Serilog.Sinks.Loki.Tests/Labels/LogLevelLabelTests.cs index 2103d3c..67ad4f3 100644 --- a/test/Serilog.Sinks.Loki.Tests/Labels/LogLevelLabelTests.cs +++ b/test/Serilog.Sinks.Loki.Tests/Labels/LogLevelLabelTests.cs @@ -17,6 +17,24 @@ public LogLevelTests() _credentials = new BasicAuthCredentials("http://test:80", "Walter", "White"); } + [Fact] + public void VerboseLabelIsSet() + { + // Arrange + var log = new LoggerConfiguration() + .MinimumLevel.Verbose() + .WriteTo.LokiHttp(_credentials, httpClient: _client) + .CreateLogger(); + + // Act + log.Verbose("Verbose Level"); + log.Dispose(); + + // Assert + var response = JsonConvert.DeserializeObject(_client.Content); + response.Streams.First().Labels.ShouldBe("{level=\"trace\"}"); + } + [Fact] public void DebugLabelIsSet() { @@ -70,5 +88,23 @@ public void ErrorLabelIsSet() var response = JsonConvert.DeserializeObject(_client.Content); response.Streams.First().Labels.ShouldBe("{level=\"error\"}"); } + + [Fact] + public void FatalLabelIsSet() + { + // Arrange + var log = new LoggerConfiguration() + .MinimumLevel.Fatal() + .WriteTo.LokiHttp(_credentials, httpClient: _client) + .CreateLogger(); + + // Act + log.Fatal("Fatal Level"); + log.Dispose(); + + // Assert + var response = JsonConvert.DeserializeObject(_client.Content); + response.Streams.First().Labels.ShouldBe("{level=\"critical\"}"); + } } } \ No newline at end of file