From c4bda3df7d83b6f1320a8763d2ce095307800369 Mon Sep 17 00:00:00 2001
From: izory <791736813@qq.com>
Date: Fri, 15 Oct 2021 13:56:29 +0800
Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Infrastructure/Attribute/LogAttribute.cs | 12 +++++++++++-
ZR.Admin.WebApi/Filters/LogActionFilter.cs | 6 ++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/Infrastructure/Attribute/LogAttribute.cs b/Infrastructure/Attribute/LogAttribute.cs
index 9250287..20df620 100644
--- a/Infrastructure/Attribute/LogAttribute.cs
+++ b/Infrastructure/Attribute/LogAttribute.cs
@@ -9,6 +9,14 @@ namespace Infrastructure.Attribute
{
public string Title { get; set; }
public BusinessType BusinessType { get; set; }
+ ///
+ /// 是否保存请求数据
+ ///
+ public bool IsSaveRequestData { get; set; } = true;
+ ///
+ /// 是否保存返回数据
+ ///
+ public bool IsSaveResponseData { get; set; } = true;
public LogAttribute() { }
@@ -16,10 +24,12 @@ namespace Infrastructure.Attribute
{
Title = name;
}
- public LogAttribute(string name, BusinessType businessType)
+ public LogAttribute(string name, BusinessType businessType, bool saveRequestData = true, bool saveResponseData = true)
{
Title = name;
BusinessType = businessType;
+ IsSaveRequestData = saveRequestData;
+ IsSaveResponseData = saveResponseData;
}
}
}
diff --git a/ZR.Admin.WebApi/Filters/LogActionFilter.cs b/ZR.Admin.WebApi/Filters/LogActionFilter.cs
index b116d74..056185b 100644
--- a/ZR.Admin.WebApi/Filters/LogActionFilter.cs
+++ b/ZR.Admin.WebApi/Filters/LogActionFilter.cs
@@ -69,13 +69,15 @@ namespace ZR.Admin.WebApi.Filters
//Elapsed = _stopwatch.ElapsedMilliseconds,
operTime = DateTime.Now
};
+ GetRequestValue(sysOperLog, context.HttpContext);
+
if (logAttribute != null)
{
sysOperLog.title = logAttribute?.Title;
sysOperLog.businessType = (int)logAttribute?.BusinessType;
+ sysOperLog.operParam = logAttribute.IsSaveRequestData ? sysOperLog.operParam : "";
+ sysOperLog.jsonResult = logAttribute.IsSaveResponseData ? sysOperLog.jsonResult : "";
}
- GetRequestValue(sysOperLog, context.HttpContext);
-
var sysOperLogService = (ISysOperLogService)App.GetRequiredService(typeof(ISysOperLogService));
sysOperLogService.InsertOperlog(sysOperLog);