我目前正在尝试在 Application Insights 中记录异常以供以后调查。 但是,我尝试使用 TrackException 方法记录的任何异常都不会出现在 Application Insights 中。
Application Insights 事件过滤的docs声明如下:
Exception - 服务器中未捕获的异常,以及您使用 TrackException() 记录的异常。
我正在使用以下代码记录我的异常:
private static readonly TelemetryClient Client = new TelemetryClient{InstrumentationKey = ApplicationInsightsSettings.InstrumentationKey};
public static void TrackException(Exception exception, string traceReference)
{
var properties = new Dictionary<string, string> {{"Trace Reference", traceReference}};
Client.TrackException(exception);
Client.TrackException(exception, properties);
Client.TrackEvent(traceReference);
}
我在 UiPath 中这样做,所以要求可能有点不同, 但是在发送异常时我不得不针对遥测客户端添加一个 Flush
telemetryClient.TrackException(in_exception);
telemetryClient.Flush();
System.Threading.Thread.Sleep(50);