Analysis of applications in debug mode

I just turned on Application Insights in my MVC application and noticed that when debugging locally, trace information is written to my Azure Application Insight.

In debug mode, I want my application to not record events in my Azure Application Insight, but still display information about events and logging in the Diagnostic Tools> Events window in Visual Studio.

I tried the following, and while this does not allow capturing events in my Azure AI, Visual Studio no longer displays debugging information in the Events window.

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

I tackled the network for an answer to no avail. Hope someone can help.

+4
source share
3 answers

The cheapest way to do this is to set the Instrumentation key for all 0. There is no NULL iKey, so it effectively just discards the message.

00000000-0000-0000-0000-000000000000

If you want to use Application_Start(), you can do this using either a directive #DEBUG, or you can use a property System.Diagnostics.Debugger.IsAttached. However, this method is not completely reliable. You can try, but your experience can be consistent.

, TelemetryInitializer, Instrumentation , . , , . , Debug , .

public class CustomeWebRequestTelemetryModule :  Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        if (telemetry != null && System.Diagnostics.Debugger.IsAttached)
        {
            telemetry.Context.InstrumentationKey = "00000000-0000-0000-0000-000000000000";
        }
    }
}
+3

, Application Insights? , Application Insights ( ), , , , .

" " - Application Insights Visual Studio Azure. . . : https://azure.microsoft.com/en-us/documentation/articles/app-insights-release-notes-vsix/#version-43

, applicationinsights.xml, 100%. ... , , .

0

@DebugThings ( ) , , 0 ikey, , , , , , AI- ikey.

"" iKey, , , iKey.

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

, "" , , , iKey - . , / , .

..:

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

there is a similar question here with similar answers: Disable application information when debugging

0
source

Source: https://habr.com/ru/post/1651306/


All Articles