我正在尝试从方法抛出的异常中读取方法名称,但是找不到解决方法。
下面是异常处理程序。
public class ExceptionLogger
{
private readonly RequestDelegate next;
public UnhandledExceptionLogger(RequestDelegate next)
{
this.next = next;
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await this.next(httpContext).ConfigureAwait(false);
}
catch (Exception ex)
{
await this.HandleException(httpContext, ex).ConfigureAwait(false);
}
}
private Task HandleException(HttpContext context, Exception exception)
{
while (exception?.InnerException != null)
{
exception = exception?.InnerException;
}
// Need to send the method name where the exception has occurred.
return context.Response.WriteAsync("");
}
}