public async Task <IActionResult> GetguestBooks(int pageIndex = 1, int pageSize = 7, bool isAsc = false) { try { int pageCount = 0; var guestCount = await guestBookService.Query(); List <GuestBook> guestbookList = new List <GuestBook>(); guestbookList = await guestBookService.QueryPage(s => s.gID > 0, x => x.gCreateTime, pageIndex, pageSize, isAsc); pageCount = guestCount.Count() % pageSize != 0 ? guestCount.Count() / pageSize + 1 : guestCount.Count() / pageSize; return(Ok(new { success = true, page = pageIndex, pageCount = pageCount, data = guestbookList })); } catch (Exception ex) { loggerHelper.Error("GuestBooksController.GetguestBooks", "异常位置:GuestBooksController.GetguestBooks" + "异常消息:" + ex.Message); return(Ok(new { success = false, message = ex.Message })); } }
public ActionResult <object> GetPersonFileInfo(string idCard) { _logger.Error(typeof(PersonController), "这是个错误日志", new Exception("123")); _logger.Error(typeof(PersonController), "这是个bug日志"); var UserFileInfo = _fileinfo.GetPersonFileInfo(idCard); return(UserFileInfo.ToJson()); }
static void ExcuteAnalyse(object obj) { try { SocketMiddleware socket = obj as SocketMiddleware; MessageBusiness messageBusiness = new MessageBusiness(socket); messageBusiness.ExcuteAnalyse(); } catch (Exception ex) { LoggerHelper.Error(typeof(Program), ex.Message, ex); Console.WriteLine(ex); } }
public async Task <IActionResult> PostAdvertisementAsync(AdvertisementInput input) { try { await _advertisementService.PostAdvertisementAsync(input); return(AddSuccessMsg()); } catch (Exception err) { _logger.Error("添加测试数据失败", err.Message); return(FailedMsg("添加测试数据失败!" + err.Message)); } }
public async Task <IActionResult> PostWx_UserOpenIdAsync([FromBody] AddUserLog dto) { try { var data = await _userService.PostWx_UserOpenIdAsync(dto.code); return(SuccessMsg("登录成功")); } catch (Exception err) { _logger.Error(typeof(UserController), "添加用户登录日志失败!", new Exception(err.Message)); return(FailedMsg("添加用户登录日志失败!" + err.Message)); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public Task OnExceptionAsync(ExceptionContext context) { if (context.Exception is BusinessException) { var result = new ObjectResult(""); result.StatusCode = 200; result.Value = new HttpResult { Success = false, Msg = context.Exception.Message }; context.Result = result; } //记录操作返回日志 var json = new JsonErrorResponse(); json.Message = context.Exception.Message; //错误信息 //if (_env.IsDevelopment()) if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } //采用log4net 进行错误日志记录 _loggerHelper.Error(json.Message, WriteLog(json.Message, context.Exception)); return(Task.CompletedTask); }
/// <summary> /// 实例化IInterceptor唯一方法 /// </summary> /// <param name="invocation">包含被拦截的方法的信息</param> public void Intercept(IInvocation invocation) { //记录被拦截方法的日志信息 Exception exception = null; var logMsg = $"{DateTime.Now:yyyyMMddHHmmss}=>当前执行方法:{invocation.TargetType.Name}_{invocation.Method.Name} 参数是:{string.Join(",", invocation.Arguments.Select(m => (m ?? "").ToString()).ToArray())}{Environment.NewLine}"; try { invocation.Proceed(); } catch (Exception e) { exception = e; logMsg += $"方法执行异"; } logMsg += $"方法执行完毕,返回结果:{invocation.ReturnValue}"; if (exception != null) { _log.Error(typeof(LogAop), logMsg, exception); } else { _log.Debug(typeof(LogAop), logMsg); } }
public async Task <IActionResult> PostRoleAsync([FromBody] AddRoleDto dto) { string openId = GetOpenId(); try { await _roleServices.PostRoleAsync(dto, openId); return(AddSuccessMsg()); } catch (Exception err) { _logger.Error(typeof(SettingController), "添加角色失败!", new Exception(err.Message)); return(FailedMsg("添加角色失败!" + err.Message)); } }
public async Task Invoke(HttpContext context) { try { await _next(context); } catch (Exception ex) { log.Error(this, ex.Message); log.Error(this, ex.StackTrace); await HandleExceptionAsync(context, context.Response.StatusCode, ex.Message); } finally { } }
public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); json.Message = context.Exception.Message;//错误信息 //返回的JSON参数 context.HttpContext.Request.Body.Position = 0; var requestReader = new StreamReader(context.HttpContext.Request.Body); var requestContent = requestReader.ReadToEnd(); string querystring = requestContent; json.ResultJson = requestContent; //接口路径 string apiPath = context.HttpContext.Request.Path.Value; //if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } context.Result = new InternalServerErrorObjectResult(json); MiniProfiler.Current.CustomTiming("Errors:", json.Message); //采用log4net 进行错误日志记录 _loggerHelper.Error(json.Message, WriteLog(json.Message, querystring, context.Exception, apiPath)); _hubContext.Clients.All.SendAsync("ReceiveUpdate", LogLock.GetLogData()).Wait(); }
public void OnException(ExceptionContext context) { // if (context.ExceptionHandled == false) // { // if (context.Exception is RequestException) // { // var ex = context.Exception as RequestException; // var errorMessage = ex.ErrorMessage; // var result = new HttpResult(ex.ErrorStatus, errorMessage); // context.Result = new ContentResult // { // Content = JsonConvert.SerializeObject(result), // StatusCode = StatusCodes.Status200OK, // ContentType = "text/html;charset=utf-8" // }; // } // LogLock.OutSql2Log("ApiErrorHandleFilter", new string[] { context.Exception.Message }); // } // context.ExceptionHandled = true; //异常已处理了 var json = new JsonErrorResponse(); json.Message = context.Exception.Message;//错误信息 if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } context.Result = new InternalServerErrorObjectResult(json); //采用log4net 进行错误日志记录 _loggerHelper.Error(json.Message, WriteLog($"当前环境:{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}" + json.Message, context.Exception)); }
public IActionResult IsLoginUserInfoes() { try { string UserName = HttpContext.Session.GetString("UserName"); int codes = 0; if (!string.IsNullOrEmpty(UserName)) { codes = 1; } return(Ok(new { success = true, code = codes, username = UserName })); } catch (Exception ex) { loggerHelper.Error("UserInfoesController.IsLoginUserInfoes", "异常位置:UserInfoesController.IsLoginUserInfoes" + "异常消息:" + ex.Message); return(Ok(new { success = false, message = ex.Message })); } }
public void OnException(ExceptionContext context) { //记录异常信息 var source = context.Exception.TargetSite.GetType().FullName; var message = context.Exception.ToString(); _loggerHelper.Error(source, message, context.Exception.GetType().FullName); context.HttpContext.Response.StatusCode = HttpStatusCode.InternalServerError.ToInt(); context.ExceptionHandled = true; }
public void OnException(ExceptionContext context) { string message = context.Exception.Message; var result = new ResultModel <string>(); result.Success = false; result.Msg = "操作失败"; context.Result = new ObjectResult(result); loggerHelper.Error(message, WriteLog(message, context.Exception)); context.ExceptionHandled = true; }
public IActionResult PostPaymentToChange([FromBody] WxPayDto dto) { string OperatorOpenId = GetOpenId(); try { var result = _payServices.PostPaymentToChange(dto, OperatorOpenId); if (result.ResultCode == ResultCode.Fail) { _logger.Error(typeof(WxPayController), result.ResultMsg); } return(Ok(result)); } catch (Exception err) { _logger.Error(typeof(WxPayController), "付款到零钱失败!", new Exception(err.Message)); return(FailedMsg("付款到零钱失败! " + err.Message)); } }
public IActionResult GetQRCodeInfo(string fileName) { try { var data = WxHelper.GetQRCodeInfo(fileName); return(SuccessData(data)); } catch (Exception err) { _logger.Error(typeof(QRCodeController), "获取发票信息失败!", new Exception(err.Message)); return(FailedMsg("获取发票信息失败!" + err.Message)); } }
public async Task <IActionResult> Getcomments() { try { var commentList = await commentService.Query(); return(Ok(new { success = true, data = commentList })); } catch (Exception ex) { loggerHelper.Error("CommentsController.Getcomments", "异常位置:CommentsController.Getcomments" + "异常消息:" + ex.Message); return(Ok(new { success = false, message = ex.Message })); } }
public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); json.Message = context.Exception.Message; if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace; } context.Result = new InternalServerErrorObjectResult(json); _loggerHelper.Error(json.Message, WriteLog(json.Message, context.Exception)); }
public async Task Invoke(HttpContext context) { try { await next(context); } catch (Exception ex) { await HandleExceptionAsync(context, ex, _env.IsDevelopment()); //记录日志 _loggerHelper.Error(ex.Message, FormatMessage(ex.Message, ex)); } }
public void OnException(ExceptionContext filterContext) { _loggerHelper.Error(filterContext.Exception.TargetSite.GetType().FullName, filterContext.Exception.ToString(), filterContext.Exception.GetType().FullName); var result = new NormalResult() { Successful = false, Code = -1, Message = $"系统异常:{filterContext?.Exception?.Message??"错误类型未知"}" }; filterContext.Result = new ObjectResult(result); filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; filterContext.ExceptionHandled = true; }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var originalBodyStream = context.Response.Body; var msg = ""; try { await next(context); } catch (WeixiaoException ex) { context.Response.StatusCode = 200; msg = ex.Message; } catch (Exception ex) { log4.Error("系统异常!", ex); logger.LogError("系统异常!", ex); msg = ex.Message; } finally { var statusCode = context.Response.StatusCode; if (statusCode == 401) { msg = "未授权"; } else if (statusCode == 404) { msg = "未找到服务"; } else if (statusCode == 502) { msg = "请求错误"; } else if (statusCode == 405) { msg = "请求方式错误"; } else if (statusCode != 200 && statusCode != 201 && statusCode != 202 && statusCode != 203 && statusCode != 204 && statusCode != 205 && statusCode != 206) { msg = "未知错误"; } if (!string.IsNullOrWhiteSpace(msg)) { await HandleExceptionAsync(context, statusCode, msg, originalBodyStream); } } }
public void OnException(ExceptionContext context) { string errorMessage = "请求参数:" + Environment.NewLine + JsonConvert.SerializeObject(context.RouteData?.Values); errorMessage += Environment.NewLine + "错误信息:" + context.Exception?.ToString(); _loggerHelper.Error(context.Exception?.TargetSite.GetType().FullName, errorMessage, context.Exception?.GetType().FullName); ApiResponse <string> apiResponse = ApiResponse <string> .GetInstance(); apiResponse.Error(context.Exception?.Message); context.Result = new ObjectResult(apiResponse); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; context.ExceptionHandled = true; }
public async Task <IActionResult> PostTeamMemberAsync([FromBody] AddTeamMemberDto dto) { var tokenInfo = GetTokenInfo(); var openId = tokenInfo.OpenId; try { var data = await _memberServices.PostTeamMemberAsync(dto, openId); return(AddSuccessMsg()); } catch (Exception err) { _logger.Error(typeof(TeamMemberController), new Exception(err.Message)); return(FailedMsg(err.Message)); } }
public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); json.Message = context.Exception.Message;//错误信息 if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } context.Result = new InternalServerErrorObjectResult(json); //MiniProfiler.Current.CustomTiming("Errors:", json.Message); //采用log4net 进行错误日志记录 _loggerHelper.Error(json.Message, WriteLog(json.Message, context.Exception)); }
public async Task Invoke(HttpContext context) { try { await next(context); } catch (Exception ex) { var statusCode = context.Response.StatusCode; if (ex is ArgumentException) { statusCode = 200; } log.Error(context, "中间件捕获异常", ex); await next(context); } }
public async Task Invoke(HttpContext httpContext) { try { await _next(httpContext); } catch (Exception ex) { _logger.Error(ex.Message, ex);//日志记录 await HandleExceptionAsync(httpContext, ex.Message); } finally { var statusCode = httpContext.Response.StatusCode; var msg = ""; switch (statusCode) { case 401: msg = "未授权"; break; case 403: msg = "拒绝访问"; break; case 404: msg = "未找到服务"; break; case 405: msg = "405 Method Not Allowed"; break; case 502: msg = "请求错误"; break; default: break; } if (!string.IsNullOrWhiteSpace(msg)) { await HandleExceptionAsync(httpContext, msg); } } }
public async Task <IActionResult> PostTeamAsync([FromBody] AddTeamDto input) { string openId = GetOpenId(); try { var data = await _teamServices.PostTeamAsync(input, openId); return(SuccessMsg()); } catch (Exception err) { _logger.Error(typeof(TeamController), "添加团队失败!", new Exception(err.Message)); return(FailedMsg("添加团队失败!" + err.Message)); } }
public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); json.Message = context.Exception.Message; if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } context.Result = new InternalServerErrorObjectResult(json); MiniProfiler.Current.CustomTiming("Errors:", json.Message); //采用log4net 进行错误日志记录 _loggerHelper.Error(json.Message, WriteLog(json.Message, context.Exception)); _hubContext.Clients.All.SendAsync("ReceiveUpdate", LogLock.GetLogData()).Wait(); }
public async Task OnExceptionAsync(ExceptionContext context) { var json = new JsonErrorResponse(); json.Message = context.Exception.Message;//错误信息 if (_env.IsDevelopment()) { json.DevelopmentMessage = context.Exception.StackTrace;//堆栈信息 } context.Result = new InternalServerErrorObjectResult(json); //采用log4net 进行错误日志记录 await Task.Run(() => { _loggerHelper.Error(json.Message, WriteLog(json.Message, context.Exception)); } ); }
public async Task Invoke(HttpContext httpContext) { try { await _next(httpContext); } catch (Exception ex) { _logger.Error(ex.Message, ex); await HandleExceptionAsync(httpContext, ex.Message); } finally { var statusCode = httpContext.Response.StatusCode; var msg = ""; switch (statusCode) { case 401: msg = "拒绝访问Web APIのアクセスが拒否されました。"; break; case 403: msg = "Web APIのアクセス権限がありません。"; break; case 404: msg = "Web APIが見つかりません。"; break; case 405: msg = "405 Method Not Allowed"; break; case 502: msg = "サーバエラー"; break; } if (!string.IsNullOrWhiteSpace(msg)) { await HandleExceptionAsync(httpContext, msg); } } }