Created
March 21, 2018 13:37
-
-
Save tugberkugurlu/cad25399d0a70933de801368088f938c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Logging; | |
namespace Zleek.Server.Common | |
{ | |
public class SlientExceptionHandlerMiddleware | |
{ | |
private readonly RequestDelegate _next; | |
private readonly ILogger _logger; | |
public SlientExceptionHandlerMiddleware(RequestDelegate next, ILogger<SlientExceptionHandlerMiddleware> logger) | |
{ | |
_next = next; | |
_logger = logger; | |
} | |
public async Task Invoke(HttpContext context) | |
{ | |
try | |
{ | |
await _next(context); | |
} | |
catch (Exception ex) | |
{ | |
_logger.LogError(0, ex, "An unhandled exception has occurred while executing the request"); | |
context.Response.StatusCode = StatusCodes.Status500InternalServerError; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment