.net core catch all exception handler

app.UseExceptionHandler(options =>
{
    options.Run(
        async context =>
        {
            var error = context.Features.Get<IExceptionHandlerFeature>();

            if (error is object)
            {
                Log.Error(
                    "EXCEPTION {method} {url} {query} => {exception}",
                    context.Request.Method,
                    context.Request.Path.Value,
                    context.Request.QueryString.Value,
                    error.Error);
            }
        });
});

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.