首页 > 解决方案 > 如何通过代码启用 EnableSqlCommandTextInstrumentation?

问题描述

根据文档,您需要将以下内容添加到applicationInsights.config文件中以启用完整的 SQL 日志记录:

<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
    <EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
</Add>

但是在我的 ASP.NET 应用程序中,在 Azure 应用程序服务中托管的 .NET Framework 4.7.2 上运行,我通过代码启用/配置 Application Insights:

TelemetryConfiguration.Active.DisableTelemetry = false;
TelemetryConfiguration.Active.InstrumentationKey = setting.ApplicationInsightsInstrumentationKey;

如何通过代码启用此设置?

PS:Web App中的设置已正确启用。

标签: c#sqlasp.netazureazure-application-insights

解决方案


似乎即使通过代码启用 AI,它也会从配置文件中获取设置。
我将它添加到我的applicationInsights.config,它现在似乎可以工作了。


推荐阅读