Application Insights在ServiceStack应用程序中使用时不跟踪异常

Lia*_*ock 5 c# servicestack azure-application-insights .net-core

我目前遇到的问题是App Insights没有在.Net Core中显示异常.我也在使用ServiceStackCore来构建我的API.

这是它在Application Insights下的Azure门户中的当前样子: Azure门户的屏幕截图

如您所见,响应代码全部显示为400,403,500.但是没有例外:

我找到了一个圆形的路线来获得例外:

var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
   telemetry.TrackException(ex);
}
Run Code Online (Sandbox Code Playgroud)
  • 我想知道ServiceStack是否有任何内置的异常处理可能会使应用程序洞察应该捕获的异常静音?

  • 如果有任何开箱即用的配置可以在App Insights中完成,以显示这些异常而无需添加try-catch块?

myt*_*thz 2

ServiceStack 允许您注册处理程序来处理异常:

public override void Configure(Container container)
{
    //Handle Exceptions occurring in Services:

    this.ServiceExceptionHandlers.Add((httpReq, request, exception) => {
        //log your exceptions here
        ...
        return null; //continue with default Error Handling

        //or return your own custom response
        //return DtoUtils.CreateErrorResponse(request, exception);
    });

    //Handle Unhandled Exceptions occurring outside of Services
    //E.g. Exceptions during Request binding or in filters:
    this.UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
         res.Write($"Error: {ex.GetType().Name}: {ex.Message}");
         res.EndRequest(skipHeaders: true);
    });
}
Run Code Online (Sandbox Code Playgroud)

ServiceExceptionHandlers因服务异常而被激发,而UncaughtExceptionHandlers因非或未知服务请求而被激发。