Azure Application Insight 未记录所有事件 - C#
static void Main(string[] args)
{
AzureHelper.LogEvent("Event1");//Static Method, logging Event1
AzureHelper.LogEvent("Event2");//Static Method, logging Event2
UpdateInformation();//Static Method working
AzureHelper.LogEvent("Event3");//Not being logged
}
//Azure Helper class
public static void LogEvent(string data)
{
try
{
telemetryClient.TrackEvent(data);
}
catch (Exception e)
{
Console.WriteLine("Exception in AppInsight" + e.Message);
}
}
我也尝试在 UpdateInformation() 中记录事件,但它也不起作用。我觉得在 UpdateInformation() 之后,appinsight 正在失去上下文。
这可能是由于应用程序在遥测数据发出之前就已结束。 Application Insights 缓冲遥测数据并偶尔将其发送到 Azure 后端。
您可以尝试使用
telemetryClient.FlushAsync()
刷新遥测:
static async Task Main(string[] args)
{
AzureHelper.LogEvent("Event1");//Static Method, logging Event1
AzureHelper.LogEvent("Event2");//Static Method, logging Event2
UpdateInformation();//Static Method working
AzureHelper.LogEvent("Event3");//Not being logged
await telemetryClient.FlushAsync();
}