I am using Azure function v3 on .net core 3.x where ILogger<T> is created through dependency injection of respective class T through IServiceProvider like ILogger<T> _log = _log = serviceProvider.GetService<ILogger<T>>();
Other than _log.LogMetric() every other log messages(traces, information, error, exception etc) are getting pushed to Application Insight. I have checked traces section of transaction search as well as traces and custom metrics of logs.
Even host.json file logging configuration seems to be correct. So what I am doing wrong?
There is a post about this on Github that suggests this is a bug. There is a workaround to inject the TelemetryClient and use client.TrackMetric();
You can do this:
services.AddSingleton<TelemetryClient>(x => new TelemetryClient(configuration.GetSection("ApplicationInsights:InstrumentationKey").Get<string>()))
The Configuration here, being your IConfiguration or IConfigurationRoot
Then after injecting into your service, just call the method, client.TrackMetric(metricName, metricValue, dictionaryProperties);
Post in question: https://github.com/Azure/azure-webjobs-sdk/issues/2308
Just a note about this, is that if you're using the TelemetryClient, you'll want to aggregate these metrics yourself with this workaround:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.applicationinsights.telemetryclient.trackmetric?view=azure-dotnet
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