Application Insights未使用CancellationToken从.Net在Azure中记录任何内容
我在使用以下代码登录到Application Insights时遇到问题:Application Insights未使用CancellationToken从.Net在Azure中记录任何内容,.net,azure-application-insights,telemetry,.net,Azure Application Insights,Telemetry,我在使用以下代码登录到Application Insights时遇到问题: var configuration = new TelemetryConfiguration(); configuration.InstrumentationKey = "KEY"; var client = new TelemetryClient(configuration); client.TrackEvent($"TEST EVENT", pr
var configuration = new TelemetryConfiguration();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);
client.TrackEvent($"TEST EVENT", properties: new Dictionary<string, string>() { { $"TEST Property", $"TEST Value".ToString() } });
有人能帮我确认一下我是否遗漏了什么吗
-Shalabh有两个可能的原因:
- 您正在创建新的
对象,它默认为没有重试/没有本地存储的简单遥测通道,因此网络问题将导致事件丢失。您可以使用从ApplicationInsights.config初始化的TelemetryConfiguration
,它将使用带有重试和本地存储的TelemetryConfiguration.Active
ServerTelemetryChannel
- 执行该方法后,应用程序可能会立即退出,从而没有机会填充遥测缓冲区并发送遥测数据。如果是这样,您可以使用
<代码>刷新()除非您已经实现,否则单独使用不会有帮助,因此您可能还需要添加一个Flush()
睡眠()
CancellationTokenSource tokenSource = new CancellationTokenSource();
CancellationToken token = tokenSource.Token;
var configuration = new TelemetryConfiguration();
configuration.InstrumentationKey = "KEY";
var client = new TelemetryClient(configuration);
while (!token.IsCancellationRequested)
{
client.TrackEvent($"TEST EVENT", properties: new Dictionary<string, string>() { { $"TEST Property", $"TEST Value".ToString() } });
}