I use ASP.NET Core json logging from Microsoft.Extensions.Logging. I can configure encoder in code like this:
builder.Logging.AddJsonConsole(config =>
{
config.JsonWriterOptions = new JsonWriterOptions { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
});
But I don't understand why it doesn't work when I try to do the same thing by using only config:
{
"Logging": {
"Console": {
"FormatterOptions": {
"JsonWriterOptions": {
"Encoder": "System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping"
}
}
}
}
}
I believe you cannot set
Encoderproperty this way because the defaultBindimplementation which bindsappsetting.jsonvalues to an object doesn't bind static properties or anything else other than plain/collection values. A custom logger provider might be useful in this case.You can however set other
JsonWriterOptionsproperties and you need to make sure to setFormatterNametojson