.NETAdmin/Infrastructure/Helper/LogMessageRegistry.cs
2025-08-01 13:57:31 +08:00

48 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using System.Text;
using System.Threading.Tasks;
namespace ZR.Infrastructure.Helper;
public static class LogMessageRegistry
{
public static readonly Dictionary<string, Func<ResultExecutedContext, string>> Templates
= new Dictionary<string, Func<ResultExecutedContext, string>>
{
["giftclaim:status"] = ctx =>
{
if (ctx.HttpContext.Request.Query.TryGetValue("id", out var idStr) &&
ctx.HttpContext.Request.Query.TryGetValue("status", out var statusStr))
{
var id = int.Parse(idStr);
int status = int.Parse(statusStr);
if (id > 0)
{
return $"礼品审核状态修改礼品兑换ID{id},修改时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},修改状态为:{(status == 1 ? "" : "")}";
}
}
return "";
}
};
/// <summary>
/// 获取日志消息模板
/// </summary>
/// <param name="key"></param>
/// <param name="client"></param>
/// <returns></returns>
public static string GetMessage(string key, ResultExecutedContext client)
{
if (!Templates.TryGetValue(key, out var func))
{
return "";
}
return func(client);
}
}