In an ASP.NET 8 web API project, the default log system (ILogger to Console) logs well the exceptions raised to the destination (AWS CloudWatch).
If I change the log format to JSON, I don’t have anymore the file path and the line number in the stack trace of my exceptions in my logs.
Here is the config to change the log format:
{
"Logging": {
"LogLevel": {
"Default": "Error"
}
},
"Console": {
"FormatterName": "json"
}
}
Here are the logs without the JSON log format:
System.InvalidOperationException: Sequence contains no elements
at DataAccess.Providers.MyProvider.GetAsync() in /Api/DataAccess/Providers/MyProvider.cs:line 12
Here are the logs with the JSON log format:
System.InvalidOperationException: Sequence contains no elements
at DataAccess.Providers.MyProvider.GetAsync()
Does anyone know why the JSON format causes the lost of the file path and line number?
Does anyone know how to workaround this issue?