Disable *all* exception handling in ASP.NET Web API 2 (to make room for my own)?

前端 未结 5 2031
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 12:21

I want to wire up exception handling in a middleware component, something like this:

public override async Task Invoke(IOwinContext context)
{
    try
    {
         


        
5条回答
  •  暖寄归人
    2020-12-02 13:02

    Here's something that might help:

    https://stackoverflow.com/a/21382651/1419853

    http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#global-error

    Essentially, there is some built in support to catch, handle, and change errors.

    It looks something like this:

    public class ExceptionLogger : System.Web.Http.ExceptionHandling.ExceptionLogger
    {
        Logger _logger;
    
        public ExceptionLogger(Logger logger)
        {
            _logger = logger;
        }
    
        public override void Log(ExceptionLoggerContext context)
        {
            _logger.Error(context.ExceptionContext.Exception.ToString());
        }
    }
    

提交回复
热议问题