/// <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) { 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); } }