增加功能:系统日志自动清理配置文件中指定月数之前的数据,使用KeepLogsPeriod配置项

This commit is contained in:
Argo-MacBookPro 2018-09-09 14:21:16 +08:00
parent 354ae823e6
commit 39fea964b5
3 changed files with 10 additions and 10 deletions

View File

@ -23,6 +23,7 @@
"DisableAutomaticKeyGeneration": false,
"AllowOrigins": "http://localhost:49823",
"KeepExceptionsPeriod": 1,
"KeepLogsPeriod": 1,
"LongbowCache": {
"CorsItems": [
{

View File

@ -21,6 +21,7 @@
"DisableAutomaticKeyGeneration": true,
"AllowOrigins": "http://localhost,http://10.15.63.218",
"KeepExceptionsPeriod": 12,
"KeepLogsPeriod": 12,
"LongbowCache": {
"Enabled": true,
"CorsItems": [

View File

@ -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
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool DeleteLog(IEnumerable<int> 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);
});
}
/// <summary>
/// 保存新增的日志信息
@ -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;
}
}