应用遥测是我的新领域。我无法将我的自定义数据发送到 Application insights 进行查询和监控。 我需要将用户 ID 指标发送给访问我用 .NET Core MVC 模型编写的 Web 应用程序的应用程序洞察力。 在从那里的文章和官方文档中引用后,我添加了一个代码,一旦我在我的控制器下添加这些自定义代码,用于发送到见解的默认数据就会停止
我尝试在控制器下添加以下代码。注意:这是为了测试我是否可以发送我自己的指标。我也添加了一些静态数据来测试。
我已经通过 DI 方法通过了 TelemetryClient
try
{
// Track a custom metric
telemetryClient.GetMetric("CustomMetricID").TrackValue(userid);
telemetryClient.GetMetric("TestMetric").TrackValue(1);
// Set the user and organization IDs
telemetryClient.Context.User.Id = userid.ToString();
// Track a custom event
var customEvent = new EventTelemetry("CustomEvent_UserID");
customEvent.Properties.Add("Int_USER_ID", userid.ToString());
customEvent.Properties.Add("Desc", "Working...");
telemetryClient.TrackEvent(customEvent);
}
catch (Exception ex)
{
telemetryClient.TrackException(ex);
}
finally
{
telemetryClient.Flush();
}
我希望将我的自定义数据(此处为 USER_ID)发送到应用程序洞察力。