1

我在 .net core 3.x 上使用 Azure 函数 v3,ILogger<T>它是通过相应类 T 的依赖注入创建的IServiceProvider like ILogger<T> _log = _log = serviceProvider.GetService<ILogger<T>>();

除了_log.LogMetric()所有其他日志消息(跟踪、信息、错误、异常等)都被推送到 Application Insight。我检查了事务搜索的跟踪部分以及日志的跟踪和自定义指标。

甚至 host.json 文件日志记录配置似乎也是正确的。那么我做错了什么?

4

2 回答 2

0

Github 上有一篇关于此的帖子,表明这是一个错误。有一种解决方法可以注入TelemetryClient和使用client.TrackMetric();

你可以这样做: services.AddSingleton<TelemetryClient>(x => new TelemetryClient(configuration.GetSection("ApplicationInsights:InstrumentationKey").Get<string>()))

这里的配置,是你的IConfigurationIConfigurationRoot

然后注入您的服务后,只需调用该方法,client.TrackMetric(metricName, metricValue, dictionaryProperties);

有问题的帖子:https ://github.com/Azure/azure-webjobs-sdk/issues/2308

请注意,如果您使用的是 TelemetryClient,您将希望自己使用此解决方法汇总这些指标:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.applicationinsights.telemetryclient.trackmetric?view=azure-dotnet

于 2021-05-20T17:45:22.797 回答
-1

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.1#log-filtering

从文档中,您会发现只有 Information、Warning、Debug、Error 和 Trace 会被推送到 Application Insight。

这五个日志级别不包含 LogMetric。

于 2020-09-03T03:41:37.940 回答