Search code examples
azure-log-analyticsmicrosoft-extensions-logging

LogMetric not working with microsoft extension framework


I am using the logging extension framework in an asp.net core function app. I have following code:

log.LogMetric("TESTER", 0);
 
log.LogInformation($"{{logTypeStart}}: {service.GetType()}", logTypeStart);
await service.Run(log);
log.LogInformation($"{{logTypeEnd}}: {service.GetType()}", logTypeEnd);

In log analytics I query following:

AppTraces
AppMetrics

The LogInformation logs traces to the AppTraces in Log Analytics. But AppMetrics does not provide any results. Any pointers on how to troubleshoot this?


Solution

  • I tested it with Function V3, the metrics can be sent to both AI and the connected Log Analytics.

    Please check the things below:

    1.Test your code first locally(please follow this thread to see how azure function and application insights works locally), and see if the metrics can be shown in visual studio output. The screenshot is as below:

    enter image description here

    2.Please make sure the Azure log Analytics is actually connected with the AI you're using.

    3.In Azure log Analytics, when query in AppMetrics table, make sure you have selected the proper time range. Here is the screenshot of my metrics:

    enter image description here

    Please let me know if any more issues.