We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The following program outputs:
{"Message":"\u3084\u304D","tako":"\u305F\u3053","yaki":"\u3084\u304D"}
using System; using System.IO; using System.Text; using Microsoft.Extensions.Logging; using ZLogger; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { using var ms = new MemoryStream(); using var loggerFactory = LoggerFactory.Create(logging => { logging.SetMinimumLevel(LogLevel.Debug); logging.AddZLoggerStream(ms, options => { options.IncludeScopes = true; options.UseJsonFormatter(formatter => { formatter.IncludeProperties = IncludeProperties.Message | IncludeProperties.ScopeKeyValues | IncludeProperties.ParameterKeyValues; }); }); }); var logger = loggerFactory.CreateLogger("test"); using var scope = logger.BeginScope("{tako}", "たこ"); var yaki = "やき"; logger.ZLogDebug($"{yaki}"); loggerFactory.Dispose(); using var sr = new StreamReader(new MemoryStream(ms.ToArray()), Encoding.UTF8); var json = sr.ReadLine(); Console.WriteLine(json); } } }
Looking into the source code, SystemTextJsonZLoggerFormatter sets JsonSerializerOptions to avoid escaping all unicode characters, but it doesn't work.
SystemTextJsonZLoggerFormatter
JsonSerializerOptions
It seems the setting should be applied to Utf8JsonWriter directly. I tried to change the code to:
Utf8JsonWriter
jsonWriter ??= new Utf8JsonWriter(writer, new JsonWriterOptions { Encoder = JsonSerializerOptions.Encoder });
Then it can output correctly:
{"Message":"やき","tako":"たこ","yaki":"やき"}
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
The following program outputs:
Looking into the source code,
SystemTextJsonZLoggerFormatter
setsJsonSerializerOptions
to avoid escaping all unicode characters, but it doesn't work.It seems the setting should be applied to
Utf8JsonWriter
directly. I tried to change the code to:Then it can output correctly:
The text was updated successfully, but these errors were encountered: