如何抛出异常的方法名称

时间:2019-07-18 10:12:10

标签: c# asp.net-core .net-core

我正在尝试从方法抛出的异常中读取方法名称,但是找不到解决方法。

下面是异常处理程序。

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("");
}
}

尝试了@@ Link1和@ Link2上提供的解决方案

0 个答案:

没有答案