We have a .net core web api and we have used inbuild logger available in Microsoft.Extensions.Logging namespace.
We have integrated this logger with Application Insight.
I can see all the logs getting logged correctly. However, I am not able to see the logging information of scope
Below is my code:
var taskId = Guid.NewGuid();
using (logger.BeginScope("Assigning Task {taskId}.",taskId))
{
logger.LogInformation("{taskId} is assigned",taskId);
}
I can see this output where scope log information is matained in '{Original Format}'. However, structured logging is not working for that field :

I have below questions:
Scopes logging works nowadays in Application Insights (I'm using version 2.19.0). Instead of passing a format string + params to BeginScope() you should pass a dictionary of name-value pairs, e.g.
using (logger.BeginScope(new Dictionary<string, object>
{ { "TaskId" = taskId }, { "Action", "AssigningTask" } }))
{
..
logger.LogInformation("{taskId} is assigned", taskId);
...
}
Here putting the taskId in the inner log message is a bit redundant, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With