/// <summary> /// 结束日志 /// </summary> /// <param name="apiLogEntity"></param> /// <param name="request"></param> /// <param name="responseModel"></param> private void _EndLog(ApiLogEntity apiLogEntity, RequestModelType request, ResponseModelType responseModel) { try { apiLogEntity.ElapsedMilliseconds = Stopwatch.ElapsedMilliseconds; apiLogEntity.RespContent = content; if (responseModel == null) { apiLogEntity.AddLogMessage("responseModel为空,EndLog将不被调用"); } else { EndLog(apiLogEntity, request, responseModel); } if (!string.IsNullOrWhiteSpace(postData)) { apiLogEntity.Params = postData; } } catch (Exception) { apiLogEntity.AddLogMessage("调用EndLog时出现异常"); } SaveLog(apiLogEntity); }
internal static string Process <RequestModelType, ResponseModelType>( Func <RequestModelType, ApiResponseModelBase, Exception, string> getErrorContent, Exception ex, RequestModelType request, ApiLogEntity apiLogEntity, ApiMethodMeta apiMethodMeta ) where RequestModelType : ApiRequestModelBase where ResponseModelType : ApiResponseModelBase { string content = string.Empty; if (ex is ApiException) { content = new ApiExceptionProcess <RequestModelType, ResponseModelType>().Process(getErrorContent, ex, request, apiLogEntity); } else if (ex is HttpException) { content = new HttpExceptionProcess <RequestModelType, ResponseModelType>().Process(getErrorContent, ex, request, apiLogEntity); } else { content = new NocatchExceptionProcess <RequestModelType, ResponseModelType>().Process(getErrorContent, ex, request, apiLogEntity); } return(content); }
/// <summary> /// 结束日志 /// </summary> /// <param name="apiLogEntity"></param> /// <param name="request"></param> /// <param name="responseModel"></param> private void _EndLog(ApiLogEntity apiLogEntity, RequestModelType request, ResponseModelType responseModel) { try { apiLogEntity.ElapsedMilliseconds = Stopwatch.ElapsedMilliseconds; apiLogEntity.RequestURL = HttpRequest.RawUrl; apiLogEntity.HttpMethod = HttpRequest.HttpMethod; EndLog(apiLogEntity, request, responseModel); } catch { } if (responseModel == null) { apiLogEntity.AddLogMessage("responseModel为空,EndLog将不被调用"); } apiLogEntity.RespContent = content ?? string.Empty; apiLogEntity.Params = postData ?? string.Empty; apiLogEntity.ElapsedMilliseconds = Stopwatch.ElapsedMilliseconds; apiLogEntity.ClientIPList = ClientIPList; apiLogEntity.TextBoxFilterItem1 = apiLogEntity.TextBoxFilterItem1 ?? ""; apiLogEntity.TextBoxFilterItem2 = apiLogEntity.TextBoxFilterItem2 ?? string.Empty; apiLogEntity.Message += $"{this.apiMethodMetaInfo.Fap}({this.apiMethodMetaInfo.APIMethodDesc.Desc})"; apiLogEntity.ModuleName = this.ApiMethodMetaInfo.Module; apiLogEntity.CategoryName = this.ApiMethodMetaInfo.Category; apiLogEntity.SubcategoryName = this.ApiMethodMetaInfo.MethodName; apiLogEntity.LogFinish(); SaveLog(apiLogEntity); }
/// <summary> /// 保存日志 /// </summary> /// <param name="apiLogEntity"></param> private void SaveLog(ApiLogEntity apiLogEntity) { if (WebBaseUtil.ApiLogger != null) { //请求IP列表 apiLogEntity.ClientIPList = new List <string> { ClientIPList }; apiLogEntity.TextBoxFilterItem1 = apiLogEntity.TextBoxFilterItem1 ?? ""; apiLogEntity.TextBoxFilterItem2 = ClientIPList ?? string.Empty; //方法名作为日志信息 if (string.IsNullOrWhiteSpace(apiLogEntity.Message)) { apiLogEntity.Message = this.apiMethodMetaInfo.APIMethodDesc.Desc ?? ""; } if (string.IsNullOrEmpty(apiLogEntity.ModuleName)) { apiLogEntity.ModuleName = this.ApiMethodMetaInfo.Module; } if (string.IsNullOrEmpty(apiLogEntity.CategoryName)) { apiLogEntity.CategoryName = this.ApiMethodMetaInfo.Category; } if (string.IsNullOrEmpty(apiLogEntity.SubcategoryName)) { apiLogEntity.SubcategoryName = this.ApiMethodMetaInfo.MethodName; } apiLogEntity.RequestURL = HttpRequest.Path; apiLogEntity.HttpMethod = HttpRequest.Method; WebBaseUtil.ApiLogger.Log(apiLogEntity); } }
/// <summary> /// 保存日志 /// </summary> /// <param name="apiLogEntity"></param> private void SaveLog(ApiLogEntity apiLogEntity) { if (WebBaseUtil.ApiLogger == null) { return; } WebBaseUtil.ApiLogger.Log(apiLogEntity); }
/// <summary> /// 开始日志 /// </summary> /// <param name="apiLogEntity"></param> /// <param name="request"></param> private void _BeginLog(ApiLogEntity apiLogEntity, RequestModelType request) { try { BeginLog(apiLogEntity, request); } catch (Exception) { } }
public string Process(Func <RequestModelType, ApiResponseModelBase, Exception, string> getErrorContent, Exception _ex, RequestModelType request, ApiLogEntity apiLogEntity) { ApiException ex = _ex as ApiException; var content = getErrorContent(request, new ApiResponseModelBase() { respCode = ex.ErrorCode, respMsg = ex.ErrorMessage }, _ex); return(content); }
public string Process(Func <RequestModelType, ApiResponseModelBase, Exception, string> getErrorContent, Exception _ex, RequestModelType request, ApiLogEntity apiLogEntity) { string exceptionId = Guid.NewGuid().ToString().Replace("-", "").ToLower(); string content = getErrorContent(request, new ApiResponseModelBase() { respCode = (int)ApiResultCode.SystemError, respMsg = string.Format("未知系统错误,异常跟踪ID[{0}]", exceptionId) }, _ex); apiLogEntity.Exception = _ex; apiLogEntity.ExceptionId = exceptionId; return(content); }
public string Process(Func <RequestModelType, ApiResponseModelBase, Exception, string> getErrorContent, Exception _ex, RequestModelType request, ApiLogEntity apiLogEntity) { HttpException ex = _ex as HttpException; string exceptionId = Guid.NewGuid().ToString("N").ToLower(); string content = getErrorContent(request, new ApiResponseModelBase() { respCode = (int)ApiResultCode.HttpError, respMsg = string.Format("请求内部接口出错,异常跟踪ID[{0}]", exceptionId) }, _ex); apiLogEntity.Exception = ex; apiLogEntity.ExceptionId = exceptionId; return(content); }
/// <summary> /// 结束日志 /// </summary> /// <param name="apiLogEntity"></param> /// <param name="request"></param> /// <param name="responseModel"></param> private void _EndLog(ApiLogEntity apiLogEntity, RequestModelType request, ResponseModelType responseModel) { apiLogEntity.ElapsedMilliseconds = Stopwatch.ElapsedMilliseconds; try { if (responseModel == null) { apiLogEntity.AddLogMessage("responseModel为空,EndLog将不被调用"); } else { EndLog(apiLogEntity, request, responseModel); } } catch (Exception) { apiLogEntity.AddLogMessage("调用EndLog时出现异常"); } }
/// <summary> /// 保存日志 /// </summary> /// <param name="apiLogEntity"></param> private void SaveLog(ApiLogEntity apiLogEntity) { try { //使用默认日记记录器 if (WebBaseUtil.ApiLogger == null) { lock (syncLock) { if (WebBaseUtil.ApiLogger == null) { WebBaseUtil.ApiLogger = new GenericLogger(); } } } WebBaseUtil.ApiLogger.Log(apiLogEntity); } catch { } }
/// <summary> /// 保存日志 /// </summary> /// <param name="apiLogEntity"></param> private void SaveLog(ApiLogEntity apiLogEntity) { //使用默认日记记录器 if (WebBaseUtil.ApiLogger == null) { WebBaseUtil.ApiLogger = new GenericLogger(); } if (WebBaseUtil.ApiLogger != null) { //请求IP列表 apiLogEntity.ClientIPList = ClientIPList != null ? ClientIPList : new List <string> { }; apiLogEntity.TextBoxFilterItem1 = apiLogEntity.TextBoxFilterItem1 ?? ""; apiLogEntity.TextBoxFilterItem2 = apiLogEntity.TextBoxFilterItem2 ?? ""; //方法名作为日志信息 if (string.IsNullOrWhiteSpace(apiLogEntity.Message)) { apiLogEntity.Message = this.apiMethodMetaInfo.APIMethodDesc.Desc ?? ""; } if (string.IsNullOrEmpty(apiLogEntity.ModuleName)) { apiLogEntity.ModuleName = this.ApiMethodMetaInfo.Module; } if (string.IsNullOrEmpty(apiLogEntity.CategoryName)) { apiLogEntity.CategoryName = this.ApiMethodMetaInfo.Category; } if (string.IsNullOrEmpty(apiLogEntity.SubcategoryName)) { apiLogEntity.SubcategoryName = this.ApiMethodMetaInfo.MethodName; } apiLogEntity.RequestURL = HttpRequest.RawUrl; apiLogEntity.HttpMethod = HttpRequest.HttpMethod; apiLogEntity.LogFinish(); WebBaseUtil.ApiLogger.Log(apiLogEntity); } }
/// <summary> /// 结束自定义日志 /// </summary> /// <param name="apiLog"></param> /// <param name="request"></param> /// <param name="responseModel"></param> public virtual void EndLog(ApiLogEntity apiLog, RequestModelType request, ResponseModelType responseModel) { }
/// <summary> /// 开始自定义日志 /// </summary> /// <param name="apiLog"></param> /// <param name="request"></param> public virtual void BeginLog(ApiLogEntity apiLog, RequestModelType request) { }