I am trying to get the method name and the class name where from exception is originated in my exception filter but unable to do so. I think because of the async methods used. I am getting MoveNext as the method instead of the actual method name.
Please find below the code
public class ExceptionFilter : ExceptionFilterAttribute
{
/// <summary>
/// Exception filter
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task OnExceptionAsync(HttpActionExecutedContext context, CancellationToken cancellationToken)
{
var s = new StackTrace(context.Exception);
var methodname=s.GetFrame(0).GetMethod().Name;
Logger.LogError(context.Exception, context.Exception.Message);
context.Response = context.Request.CreateResponse(HttpStatusCode.OK, res);
return Task.CompletedTask;
}
}
I searched a lot but couln't find any answer. Any help would be appreciable.