public async Task Invoke(HttpContext context) { try { await this.next(context); } catch (Exception ex) { await HandleExceptionAsync(context, ex); } } private async Task HandleExceptionAsync(HttpContext context, Exception exception) { // Populate ExceptionLogEntry... // Write a new error entry in the logs... // Return a clean HTTP 500 response to the client... }