Application Insights 不记录 SQL 依赖关系查询

fro*_*sty 2 azure-application-insights asp.net-core .net-5

我正在使用使用 Asp.Net Core 和 .Net5 在 Azure 中托管的应用程序服务。我使用 appSettings.config 中的以下设置打开了 SQL 依赖项跟踪。但我看到没有 SQL 命令文本记录 SQL 依赖关系。是否还有其他设置可以在日志中查看 SQL 命令?

  "ApplicationInsights": {
    "InstrumentationKey": "my guid key",
    "EnableDependencyTracking": true,
    "DependencyTrackingOptions": {
      "EnableSqlCommandTextInstrumentation": true
    },
    "sampling": {
      "isEnabled": true,
      "maxTelemetryItemsPerSecond": 5
    }
  },
Run Code Online (Sandbox Code Playgroud)

Jas*_*Pan 6

您的设置appSettings.config是用于Azure Function,而不是ASP.NET Core applications

对于 ASP.NET Core 应用程序,现在需要使用以下方法选择加入 SQL 文本集合

services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) => { module. EnableSqlCommandTextInstrumentation = true; });
Run Code Online (Sandbox Code Playgroud)

更详细的内容可以参考官方文档

高级 SQL 跟踪以获得完整的 SQL 查询