Admin.Core/src/platform/ZhonTai.Admin/Core/Logs/LogHandler.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using ZhonTai.Admin.Services.OprationLog;
using ZhonTai.Admin.Services.OprationLog.Dto;
namespace ZhonTai.Admin.Core.Logs;
/// <summary>
/// 操作日志处理
/// </summary>
public class LogHandler : ILogHandler
{
private readonly ILogger _logger;
private readonly ApiHelper _apiHelper;
private readonly IOprationLogService _oprationLogService;
public LogHandler(
ILogger<LogHandler> logger,
ApiHelper apiHelper,
IOprationLogService oprationLogService
)
{
_logger = logger;
_apiHelper = apiHelper;
_oprationLogService = oprationLogService;
}
public async Task LogAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var sw = new Stopwatch();
sw.Start();
var actionExecutedContext = await next();
sw.Stop();
//操作参数
//var args = JsonConvert.SerializeObject(context.ActionArguments);
//操作结果
//var result = JsonConvert.SerializeObject(actionResult?.Value);
try
{
var input = new OprationLogAddInput
{
Status = true,
ApiMethod = context.HttpContext.Request.Method.ToLower(),
ApiPath = context.ActionDescriptor.AttributeRouteInfo.Template.ToLower(),
ElapsedMilliseconds = sw.ElapsedMilliseconds
};
if (actionExecutedContext.Exception != null)
{
input.Status = false;
input.Msg = actionExecutedContext.Exception.Message;
}
input.ApiLabel = _apiHelper.GetApis().FirstOrDefault(a => a.Path == input.ApiPath)?.Label;
后面还有 9 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
