Skip to content

Commit 71604ec

Browse files
committed
RenderedCompactJsonFormatter, for environments without message templates
1 parent de8377b commit 71604ec

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ Log.Logger = new LoggerConfiguration()
2626
.CreateLogger();
2727
```
2828

29-
### Format details
29+
### Rendered events
30+
31+
`CompactJsonFormatter` will preserve the message template, properties, and formatting information so that the rendered message can be created at a later point. When the
32+
JSON is intended for consumption in an environment without message template rendering, `RenderedCompactJsonFormatter` can be used instead.
3033

31-
The format written by `CompactJsonFormatter` is specified generically so that implementations for other logging libraries, including _Microsoft.Extensions.Logging_, are possible if desired.
34+
Instead of the message template, `RenderedCompactJsonFormatter` writes the fully-rendered message, as well as
35+
an _event id_ [generated from the message template](https://nblumhardt.com/2015/10/assigning-event-types-to-serilog-events/), into the event.
36+
37+
### Format details
3238

33-
The implementation in this repository obeys the specification but does not yet support the `@m` (rendered message) property, and has no need for the `@i` (event id) property.
39+
The format written by the compact formatters is specified generically so that implementations for other logging libraries, including _Microsoft.Extensions.Logging_, are possible if desired.
3440

3541
##### Payload
3642

test/Serilog.Formatting.Compact.Tests/CompactJsonFormatterTests.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32
using Newtonsoft.Json.Linq;
43
using Xunit;
54
using Serilog.Formatting.Compact.Tests.Support;
@@ -11,18 +10,7 @@ public class CompactJsonFormatterTests
1110
{
1211
JObject AssertValidJson(Action<ILogger> act)
1312
{
14-
var output = new StringWriter();
15-
var formatter = new CompactJsonFormatter();
16-
var log = new LoggerConfiguration()
17-
.WriteTo.Sink(new TextWriterSink(output, formatter))
18-
.CreateLogger();
19-
20-
act(log);
21-
22-
var json = output.ToString();
23-
24-
// Unfortunately this will not detect all JSON formatting issues; better than nothing however.
25-
return JObject.Parse(json);
13+
return Assertions.AssertValidJson(new CompactJsonFormatter(), act);
2614
}
2715

2816
[Fact]

0 commit comments

Comments
 (0)