diff --git a/Bootstrap.Admin/appsettings.Development.json b/Bootstrap.Admin/appsettings.Development.json
index 49f2c286..2c6ee5f1 100644
--- a/Bootstrap.Admin/appsettings.Development.json
+++ b/Bootstrap.Admin/appsettings.Development.json
@@ -23,6 +23,7 @@
"DisableAutomaticKeyGeneration": false,
"AllowOrigins": "http://localhost:49823",
"KeepExceptionsPeriod": 1,
+ "KeepLogsPeriod": 1,
"LongbowCache": {
"CorsItems": [
{
diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json
index 6fd31a07..6ba22465 100644
--- a/Bootstrap.Admin/appsettings.json
+++ b/Bootstrap.Admin/appsettings.json
@@ -21,6 +21,7 @@
"DisableAutomaticKeyGeneration": true,
"AllowOrigins": "http://localhost,http://10.15.63.218",
"KeepExceptionsPeriod": 12,
+ "KeepLogsPeriod": 12,
"LongbowCache": {
"Enabled": true,
"CorsItems": [
diff --git a/Bootstrap.DataAccess/LogHelper.cs b/Bootstrap.DataAccess/LogHelper.cs
index effbd534..9afd1007 100644
--- a/Bootstrap.DataAccess/LogHelper.cs
+++ b/Bootstrap.DataAccess/LogHelper.cs
@@ -1,9 +1,9 @@
using Longbow.Cache;
+using Longbow.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
-using System.Globalization;
using System.Linq;
namespace Bootstrap.DataAccess
@@ -48,17 +48,14 @@ namespace Bootstrap.DataAccess
///
///
///
- public static bool DeleteLog(IEnumerable value)
+ public static void DeleteLogAsync()
{
- bool ret = false;
- var ids = string.Join(",", value);
- string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Logs where ID in ({0})", ids);
- using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ System.Threading.Tasks.Task.Run(() =>
{
- ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
- CacheCleanUtility.ClearCache(logIds: ids);
- }
- return ret;
+ string sql = $"delete from Logs where LogTime < DATEADD(MONTH, -{ConfigurationManager.AppSettings["KeepLogsPeriod"]}, GETDATE())";
+ DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
+ });
}
///
/// 保存新增的日志信息
@@ -80,6 +77,7 @@ namespace Bootstrap.DataAccess
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(logIds: p.Id == 0 ? string.Empty : p.Id.ToString());
+ DeleteLogAsync();
return ret;
}
}