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); + } } }