Skip to content

Commit 31d1d65

Browse files
committed
Fixed JSON formatting with message rendering enabled
1 parent b5b8fe2 commit 31d1d65

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/Serilog.Sinks.Splunk/Sinks/Splunk/SplunkJsonFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void Format(LogEvent logEvent, TextWriter output)
109109

110110
if (_renderTemplate)
111111
{
112-
output.Write("\",\"MessageTemplate\":");
112+
output.Write(",\"MessageTemplate\":");
113113
JsonValueFormatter.WriteQuotedJsonString(logEvent.MessageTemplate.Text, output);
114114
}
115115

test/Serilog.Sinks.Splunk.Tests/SplunkJsonFormatterTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ public class SplunkJsonFormatterTests
1010
{
1111
void AssertValidJson(Action<ILogger> act)
1212
{
13-
var output = new StringWriter();
14-
var formatter = new SplunkJsonFormatter(false, null);
13+
StringWriter outputRendered = new StringWriter(), output = new StringWriter();
1514
var log = new LoggerConfiguration()
16-
.WriteTo.Sink(new TextWriterSink(output, formatter))
15+
.WriteTo.Sink(new TextWriterSink(output, new SplunkJsonFormatter(false, null)))
16+
.WriteTo.Sink(new TextWriterSink(outputRendered, new SplunkJsonFormatter(true, null)))
1717
.CreateLogger();
1818

1919
act(log);
2020

21-
var json = output.ToString();
22-
2321
// Unfortunately this will not detect all JSON formatting issues; better than nothing however.
24-
JObject.Parse(json);
22+
JObject.Parse(output.ToString());
23+
JObject.Parse(outputRendered.ToString());
2524
}
2625

2726
[Fact]

0 commit comments

Comments
 (0)