Custom Metrics don't seem to work when using DI with typed ILoggers
See original GitHub issueFunction App v2.0
I am using Dependency Injection via FunctionsStartup, and my services request an ILogger<T>
, which seems to be working for trace-logging, but not for metrics.
I have tried a few different variations of my host.json file to see if it is a problem with my logging filters, but nothing so far has worked. Even when I set the default filter to “Debug”, no custom metrics show up in Application Insights.
"logLevel": {
"default": "Debug"
}
I am logging metrics using the LogMetric
extension method on ILogger from the Microsoft.Extensions.Logging NuGet package. This all worked fine before switching over to using an injected ILogger<T> instead of the ILogger supplied in the Run() method.
Interestingly enough, I can see some trace-logs in Application Insights that seem to correspond with my custom metric logs. There are empty messages in the log analytics that have LogLevel Information and customDimensions “prop__Name” and “prop__Value” that are the same as my metrics. So it seems like the actual messages are coming through the filters but are not being correctly identified as being metrics.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:11 (2 by maintainers)
Top GitHub Comments
Any update on this.
This is a bug. We currently only apply the metrics if it comes from our logger that we pass in. We check the category/event pair. When you inject a logger, that category isn’t what we expect.
One workaround – you could request a
TelemetryClient
in your class constructor (DI will inject it) and log your metrics directly via that.