Skip to content

Commit

Permalink
Merge pull request #185 from AlanLiu90/master
Browse files Browse the repository at this point in the history
Fix unicode characters are escaped
  • Loading branch information
neuecc authored Nov 20, 2024
2 parents 675d0ff + 223dc28 commit e2a1a56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ZLogger/Formatters/SystemTextJsonZLoggerFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ public class SystemTextJsonZLoggerFormatter : IZLoggerFormatter
public void FormatLogEntry(IBufferWriter<byte> writer, IZLoggerEntry entry)
{
jsonWriter?.Reset(writer);
jsonWriter ??= new Utf8JsonWriter(writer);
jsonWriter ??= new Utf8JsonWriter(writer, new JsonWriterOptions()
{
Indented = JsonSerializerOptions.WriteIndented,
Encoder = JsonSerializerOptions.Encoder,
SkipValidation = true,
#if NET7_0_OR_GREATER
MaxDepth = JsonSerializerOptions.MaxDepth
#endif
});

jsonWriter.WriteStartObject();

Expand Down
2 changes: 2 additions & 0 deletions tests/ZLogger.Tests/JsonFormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void FormatLogEntry_CustomMetadata()

doc.GetProperty("Hash").GetString().Should().Be(sourceCodeHash);
doc.GetProperty("LogLevel").GetString().Should().Be("Debug");

json.Should().NotContainAny("\\u");
}

[Fact]
Expand Down

0 comments on commit e2a1a56

Please sign in to comment.