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, eg
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.