From 8a26a4aeece53f43c11e1f975f1890a0f7d01e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 15 Dec 2024 11:32:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dpure=E8=8B=A5=E5=B9=B2?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Operlog/OperLogGlobalAttribute.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Operlog/OperLogGlobalAttribute.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Operlog/OperLogGlobalAttribute.cs index a2f0ac0c..3fe445b7 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Operlog/OperLogGlobalAttribute.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Operlog/OperLogGlobalAttribute.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories; +using Volo.Abp.Uow; using Volo.Abp.Users; using Yi.Framework.Core.Extensions; using Yi.Framework.Core.Helper; @@ -18,12 +19,15 @@ namespace Yi.Framework.Rbac.Domain.Operlog private ILogger _logger; private IRepository _repository; private ICurrentUser _currentUser; + + private IUnitOfWorkManager _unitOfWorkManager; //注入一个日志服务 - public OperLogGlobalAttribute(ILogger logger, IRepository repository, ICurrentUser currentUser) + public OperLogGlobalAttribute(ILogger logger, IRepository repository, ICurrentUser currentUser, IUnitOfWorkManager unitOfWorkManager) { _logger = logger; _repository = repository; _currentUser = currentUser; + _unitOfWorkManager = unitOfWorkManager; } public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) @@ -35,8 +39,9 @@ namespace Yi.Framework.Rbac.Domain.Operlog if (resultContext.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return; //查找标签,获取标签对象 - OperLogAttribute? operLogAttribute = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true) - .FirstOrDefault(a => a.GetType().Equals(typeof(OperLogAttribute))) as OperLogAttribute; + OperLogAttribute? operLogAttribute = controllerActionDescriptor.MethodInfo + .GetCustomAttributes(inherit: true) + .FirstOrDefault(a => a.GetType().Equals(typeof(OperLogAttribute))) as OperLogAttribute; //空对象直接返回 if (operLogAttribute is null) return; @@ -48,7 +53,7 @@ namespace Yi.Framework.Rbac.Domain.Operlog //获取Ip string ip = resultContext.HttpContext.GetClientIp(); - //根据ip获取地址 + //根据ip获取地址 string location = ""; try { @@ -78,6 +83,7 @@ namespace Yi.Framework.Rbac.Domain.Operlog { logEntity.RequestResult = result.Content?.Replace("\r\n", "").Trim(); } + if (resultContext.Result is JsonResult result2) { logEntity.RequestResult = result2.Value?.ToString(); @@ -92,14 +98,13 @@ namespace Yi.Framework.Rbac.Domain.Operlog if (operLogAttribute.IsSaveRequestData) { - //不建议保存,吃性能 - //保存请求参数 logEntity.RequestParam = JsonConvert.SerializeObject(context.ActionArguments); } - await _repository.InsertAsync(logEntity); - - + using (var uow = _unitOfWorkManager.Begin()) + { + await _repository.InsertAsync(logEntity); + } } }