Skip to content

Commit e2a1a56

Browse files
authored
Merge pull request #185 from AlanLiu90/master
Fix unicode characters are escaped
2 parents 675d0ff + 223dc28 commit e2a1a56

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ZLogger/Formatters/SystemTextJsonZLoggerFormatter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ public class SystemTextJsonZLoggerFormatter : IZLoggerFormatter
132132
public void FormatLogEntry(IBufferWriter<byte> writer, IZLoggerEntry entry)
133133
{
134134
jsonWriter?.Reset(writer);
135-
jsonWriter ??= new Utf8JsonWriter(writer);
135+
jsonWriter ??= new Utf8JsonWriter(writer, new JsonWriterOptions()
136+
{
137+
Indented = JsonSerializerOptions.WriteIndented,
138+
Encoder = JsonSerializerOptions.Encoder,
139+
SkipValidation = true,
140+
#if NET7_0_OR_GREATER
141+
MaxDepth = JsonSerializerOptions.MaxDepth
142+
#endif
143+
});
136144

137145
jsonWriter.WriteStartObject();
138146

tests/ZLogger.Tests/JsonFormatTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public void FormatLogEntry_CustomMetadata()
5252

5353
doc.GetProperty("Hash").GetString().Should().Be(sourceCodeHash);
5454
doc.GetProperty("LogLevel").GetString().Should().Be("Debug");
55+
56+
json.Should().NotContainAny("\\u");
5557
}
5658

5759
[Fact]

0 commit comments

Comments
 (0)