方法1:继承IExceptionLogger
ExceptionLogger是框架提供的表示未处理的异常记录器的抽象类
public class RecordExceptionLogger : ExceptionLogger { public void LogCore(ExceptionLoggerContext context) { var request = context.Request; LogUtil.WriteLog(request, context.Exception); } public override async Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken) { await Task.Run(() => LogCore(context), cancellationToken); } }
参考