When our GraphQL server responds with a InternalServerError, no logs are being produced; leading to unknown bugs.
I’ve added some middleware to handle the expection but nothing appears to be logging, and only half works.
Program.cs – Adding Middleware
app.UseMiddleware<ExceptionLoggerMiddleware>();
ExceptionLoggerMiddleware.cs – Exception Handler
using Serilog;
namespace Example.common;
public class ExceptionLoggerMiddleware
{
private readonly RequestDelegate _next;
public ExceptionLoggerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
Log.Error(ex, "An unhandled exception occured");
throw;
}
}
}
Any advice or suggestions would be greatly appriecated !