I need to log custom dimensions to Application Insights
for which I'm using ILogger.BeginScope()
. That works perfectly. That is:
using (logger.BeginScope(new Dictionary<string, object> { "key": "value" }))
{
logger.LogInformation("message");
}
My issue is that I need to call other methods in other classes, and I'm injecting the ILogger
into all my classes. So how can I persist the logging scope among all my classes?
I could surely do ILogger.BeginScope()
in all my classes, but I would need to pass the custom properties to classes that don't really need that information. Is there a pattern I could use?