优化全局过滤器日志记录

This commit is contained in:
不做码农
2022-03-04 21:49:18 +08:00
parent 76c53b9915
commit 314eb40ed9
7 changed files with 140 additions and 38 deletions

View File

@@ -6,8 +6,10 @@ using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UAParser;
@@ -161,6 +163,32 @@ namespace ZR.Admin.WebApi.Extensions
});
}).Wait();
}
/// <summary>
/// 设置请求参数
/// </summary>
/// <param name="operLog"></param>
/// <param name="context"></param>
public static void GetRequestValue(this HttpContext context, SysOperLog operLog)
{
string reqMethod = operLog.requestMethod;
string param;
if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod))
{
context.Request.Body.Seek(0, SeekOrigin.Begin);
using var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
//需要使用异步方式才能获取
param = reader.ReadToEndAsync().Result;
}
else
{
param = context.Request.QueryString.Value.ToString();
}
operLog.operParam = param;
}
}
}