azure webjob java_将Azure Application Insights与Azure WebJob一起使用

徐奇
2023-12-01

我编写了一个通过Application Insights跟踪事件和指标的控制台应用程序,我认为通过添加以下NuGet包,WebJob将完全不同:

Microsoft.ApplicationInsights

Microsoft.ApplicationInsights.TraceListener(可能不需要)

我的 ApplicationInsights.config 看起来像这样:

简单的程序就是这样做的:

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

 类似资料: