private async Task HandleException(HttpContext context, Exception e) { context.Response.ContentType = "text/json;charset=utf-8;"; if (Regex.IsMatch(context.Request.Path.Value.ToLower(), "/api/*/*")) { var data = new ApiResultModel() { StatusCode = 500, ErrorMessage = e.Message, Data = new object[] { }, IsSuccess = false }; await context.Response.WriteAsync(data.ToJson()); } else { var data = new AjaxResult { state = "error", message = e.Message }; await context.Response.WriteAsync(data.ToJson()); } var errorMsg = $"【抛出信息】:{e.Message} \r\n【异常类型】:{e.GetType().Name} \r\n【异常信息】:{e.Message} \r\n【堆栈调用】:\r\n{e.StackTrace}"; _logger.LogError(errorMsg); }