调试模式下的应用程序洞察

时间:2016-08-15 16:53:35

标签: c# azure visual-studio-2015 azure-application-insights

我刚刚在我的MVC应用程序中启用了Application Insights,并注意到在本地调试时,我的Azure Application Insight中正在捕获跟踪信息。

在调试模式下,我想阻止我的应用程序在Azure Application Insight中记录事件,但仍然在诊断工具>中显示事件和日志记录信息。 Visual Studio中的事件窗口。

我尝试了以下操作,虽然这样可以阻止在我的Azure AI中捕获事件,但Visual Studio不再在“事件”窗口中显示调试信息。

 protected void Application_Start()
 {
        #if DEBUG
        TelemetryConfiguration.Active.DisableTelemetry = true;
        #endif
 }

我在网上上网找不到答案。希望有人可以提供帮助。

1 个答案:

答案 0 :(得分:0)

@DebugThings答案(大部分)会起作用,但如果您使用0来表示ikey,那么可能仍在发送遥测,但它可能< / em>也被AI后端拒绝为无效的ikey。

就个人而言,最好的解决方案是创建一个单独的&#34;调试&#34; iKey,在内置调试模式的代码中,使用iKey代替。

protected void Application_Start()
{
    #if DEBUG
    TelemetryConfiguration.Active.InstrumentationKey = "your debug ikey";
    #endif
}

这样,您可以&#34;调试&#34;在不污染生产环境的情况下发送的任何遥测,在发布版本中,仍会使用配置文件中的iKey。这样,您就可以确保在不使用此时允许的固定号码的情况下发送正确的自定义属性/指标。

这是一篇关于使用配置根据环境等将数据发送到不同地方的博客文章:

https://blogs.msdn.microsoft.com/visualstudioalm/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions/

这里有一个类似的问题,答案相似: Disable application insights in debug