-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
Using the json structured log with the intent to collect them from all containers without having to parse them, the message appears twice in full (bug) plus a third with the original format.
Either I missed the documentation or there is no way to configure what appears in the structure (with the built-in logger).
One could say I can writer a logger, but is it really the purpose of reinventing the wheel ... again ?
Reproduction Steps
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddJsonConsole((JsonConsoleFormatterOptions options) => {
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffffffzzz";
options.JsonWriterOptions = new JsonWriterOptions {
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping // Because + is a dangerous character
};
});
Expected behavior
I am expecting, out-of-the-box, logging that contain usable information but without repetition.
Actual behavior
Here is an indented version of a single log line.
{
"Timestamp": "2024-07-04T01:11:36.9360021+02:00",
"EventId": 2,
"LogLevel": "Information",
"Category": "Microsoft.AspNetCore.Hosting.Diagnostics",
"Message": "Request finished HTTP/1.1 GET http://venium:8076/api/really/anything - 200 54 text/plain;charset=utf-8 17.1633ms",
"State": {
"Message": "Request finished HTTP/1.1 GET http://venium:8076/api/really/anything - 200 54 text/plain;charset=utf-8 17.1633ms",
"ElapsedMilliseconds": 17.1633,
"StatusCode": 200,
"ContentType": "text/plain; charset=utf-8",
"ContentLength": 54,
"Protocol": "HTTP/1.1",
"Method": "GET",
"Scheme": "http",
"Host": "venium:8076",
"PathBase": "",
"Path": "/api/really/anything",
"QueryString": "",
"{OriginalFormat}": "Request finished {Protocol} {Method} {Scheme}://{Host}{PathBase}{Path}{QueryString} - {StatusCode} {ContentLength} {ContentType} {ElapsedMilliseconds}ms"
}
}
The message appears 2 times in plain text (this is a bug).
It appears a third time in the form of the original format which should be disableable in the options (JsonConsoleFormatterOptions).
Regression?
With x services times y nodes, it generates an unnecessary volume of logs leading back to a text-based log, custom logger or thirdparty solution while the information is already there.
Known Workarounds
As mentioned above, custom or thirdparty logger, but what is the framework for then ?
Configuration
I am using net8.0 on Windows 10/11 x64 (dev) and Unix 5.10 (prod).
Other information
I surfed a while now about the subject and did not found mention of this issue (duplicate message in single log).
If it is a duplicate, sorry for that and please point me to it.