Use Azure Application Insights with Azure WebJob

后端 未结 2 1583
闹比i
闹比i 2020-12-30 21:00

The Azure documentation covers many examples of integrating Azure Application Insights into different applications types, such as ASP.NET, Java, etc. However, the documentat

2条回答
  •  旧巷少年郎
    2020-12-30 21:13

    I have written a console application that tracks events and metrics via Application Insights, and I figure a WebJob won't be all that different, by adding the following NuGet packages:

    • Microsoft.ApplicationInsights
    • Microsoft.ApplicationInsights.TraceListener (this may not be required)

    My ApplicationInsights.config looks like this:

    
        
            
        
    
    

    And the simple program does this:

    TelemetryConfiguration.Active.InstrumentationKey = "the_key";
    TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;
    
    var tc = new TelemetryClient();
    tc.TrackRequest("Track Some Request", DateTimeOffset.UtcNow, new TimeSpan(0, 0, 3), "200", true);
    tc.TrackMetric("XYZ Metric", 100);
    tc.TrackEvent("Tracked Event");
    
    tc.Flush(); //need to do this, otherwise if the app exits the telemetry data won't be sent
    

    There is also this: Application Insights on Windows Desktop apps, services and worker roles

提交回复
热议问题