Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created March 21, 2018 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/cad25399d0a70933de801368088f938c to your computer and use it in GitHub Desktop.
Save tugberkugurlu/cad25399d0a70933de801368088f938c to your computer and use it in GitHub Desktop.
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