Why does this code only gets executed when no error has occurred?
app.Use(async (context, next) => {
Console.WriteLine(context.RequestAborted.IsCancellationRequested);
if(context.Response.StatusCode < 200 || context.Response.StatusCode > 299) {
Console.WriteLine();
Console.WriteLine(context.Request.Method);
Console.WriteLine(context.Request.Path);
}
await next.Invoke();
});
Is there an easy way to log the url and optionally body of the request when an unhandled exception occurs?