当启用Application Insights请求遥测中间件时,它会抛出所有类型的异常而不会结束。这不是以前的问题。
Startup.ConfigureServices配置:
var appInsightsConfiguration = new ConfigurationBuilder()
.AddApplicationInsightsSettings(
developerMode: true,
instrumentationKey: Configuration["ApplicationInsights:Key"])
.Build();
services.AddApplicationInsightsTelemetry(appInsightsConfiguration);
将中间件添加到管道的开头:
app.UseApplicationInsightsRequestTelemetry();
我们使用的是Microsoft.ApplicationInsights.AspNetCore
的1.0.0。
抛出的异常看起来像这样:
{System.Net.WebException:远程服务器返回错误:(400) 错误的请求。在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)}
{System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)}