perf: 优化操作日志方式
This commit is contained in:
@@ -7,6 +7,7 @@ using Yi.Framework.Ddd.Dtos;
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||||
using Yi.RBAC.Domain.Identity.Entities;
|
using Yi.RBAC.Domain.Identity.Entities;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Yi.RBAC.Application.Setting
|
namespace Yi.RBAC.Application.Setting
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,7 @@ namespace Yi.RBAC.Application.Setting
|
|||||||
/// Config服务实现
|
/// Config服务实现
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AppService]
|
[AppService]
|
||||||
|
|
||||||
public class ConfigService : CrudAppService<ConfigEntity, ConfigGetOutputDto, ConfigGetListOutputDto, long, ConfigGetListInputVo, ConfigCreateInputVo, ConfigUpdateInputVo>,
|
public class ConfigService : CrudAppService<ConfigEntity, ConfigGetOutputDto, ConfigGetListOutputDto, long, ConfigGetListInputVo, ConfigCreateInputVo, ConfigUpdateInputVo>,
|
||||||
IConfigService, IAutoApiService
|
IConfigService, IAutoApiService
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Yi.Framework.AspNetCore.Extensions;
|
using Yi.Framework.AspNetCore.Extensions;
|
||||||
|
using Yi.Framework.Core.CurrentUsers;
|
||||||
|
using Yi.Framework.Ddd.Repositories;
|
||||||
|
using Yi.Framework.Model.RABC.Entitys;
|
||||||
using Yi.RBAC.Domain.Shared.Logs;
|
using Yi.RBAC.Domain.Shared.Logs;
|
||||||
|
|
||||||
namespace Yi.RBAC.Domain.Logs
|
namespace Yi.RBAC.Domain.Logs
|
||||||
@@ -16,13 +19,17 @@ namespace Yi.RBAC.Domain.Logs
|
|||||||
public class GlobalOperLogAttribute : ActionFilterAttribute
|
public class GlobalOperLogAttribute : ActionFilterAttribute
|
||||||
{
|
{
|
||||||
private ILogger<GlobalOperLogAttribute> _logger;
|
private ILogger<GlobalOperLogAttribute> _logger;
|
||||||
|
private IRepository<OperationLogEntity> _repository;
|
||||||
|
private ICurrentUser _currentUser;
|
||||||
//注入一个日志服务
|
//注入一个日志服务
|
||||||
public GlobalOperLogAttribute(ILogger<GlobalOperLogAttribute> logger)
|
public GlobalOperLogAttribute(ILogger<GlobalOperLogAttribute> logger, IRepository<OperationLogEntity> repository,ICurrentUser currentUser)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_repository = repository;
|
||||||
|
_currentUser=currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnResultExecuted(ResultExecutedContext context)
|
public override async void OnResultExecuted(ResultExecutedContext context)
|
||||||
{
|
{
|
||||||
//判断标签是在方法上
|
//判断标签是在方法上
|
||||||
if (context.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return;
|
if (context.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor) return;
|
||||||
@@ -49,41 +56,42 @@ namespace Yi.RBAC.Domain.Logs
|
|||||||
|
|
||||||
//日志服务插入一条操作记录即可
|
//日志服务插入一条操作记录即可
|
||||||
|
|
||||||
//var logEntity = new OperationLogEntity();
|
var logEntity = new OperationLogEntity();
|
||||||
|
logEntity.Id = SnowflakeHelper.NextId;
|
||||||
//logEntity.OperIp = ip;
|
logEntity.OperIp = ip;
|
||||||
////logEntity.OperLocation = location;
|
|
||||||
//logEntity.OperType = logAttribute.OperType.GetHashCode();
|
|
||||||
//logEntity.Title = logAttribute.Title;
|
|
||||||
//logEntity.RequestMethod = context.HttpContext.Request.Method;
|
|
||||||
//logEntity.Method = context.HttpContext.Request.Path.Value;
|
|
||||||
//logEntity.IsDeleted = false;
|
|
||||||
//logEntity.OperUser= context.HttpContext.GetUserNameInfo();
|
|
||||||
//logEntity.OperLocation = location;
|
//logEntity.OperLocation = location;
|
||||||
//if (logAttribute.IsSaveResponseData)
|
logEntity.OperType = operLogAttribute.OperType;
|
||||||
//{
|
logEntity.Title = operLogAttribute.Title;
|
||||||
// if (context.Result is ContentResult result && result.ContentType == "application/json")
|
logEntity.RequestMethod = context.HttpContext.Request.Method;
|
||||||
// {
|
logEntity.Method = context.HttpContext.Request.Path.Value;
|
||||||
// logEntity.RequestResult = result.Content?.Replace("\r\n", "").Trim();
|
logEntity.OperLocation = location;
|
||||||
// }
|
|
||||||
// if (context.Result is JsonResult result2)
|
|
||||||
// {
|
|
||||||
// logEntity.RequestResult = result2.Value?.ToString();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (context.Result is ObjectResult result3)
|
|
||||||
// {
|
|
||||||
// logEntity.RequestResult = JsonHelper.ObjToStr(result3.Value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
logEntity.OperUser = _currentUser.UserName;
|
||||||
|
if (operLogAttribute.IsSaveResponseData)
|
||||||
|
{
|
||||||
|
if (context.Result is ContentResult result && result.ContentType == "application/json")
|
||||||
|
{
|
||||||
|
logEntity.RequestResult = result.Content?.Replace("\r\n", "").Trim();
|
||||||
|
}
|
||||||
|
if (context.Result is JsonResult result2)
|
||||||
|
{
|
||||||
|
logEntity.RequestResult = result2.Value?.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
//if (logAttribute.IsSaveRequestData)
|
if (context.Result is ObjectResult result3)
|
||||||
//{
|
{
|
||||||
// logEntity.RequestParam = context.HttpContext.GetRequestValue(logEntity.RequestMethod);
|
logEntity.RequestResult = JsonHelper.ObjToStr(result3.Value);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//_operationLogService._repository.InsertReturnSnowflakeId(logEntity);
|
}
|
||||||
|
|
||||||
|
if (operLogAttribute.IsSaveRequestData)
|
||||||
|
{
|
||||||
|
//logEntity.RequestParam = context.HttpContext.GetRequestValue(logEntity.RequestMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _repository.InsertAsync(logEntity);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user