using Longbow; using Longbow.Configuration; using System; using System.Collections.Generic; namespace Bootstrap.DataAccess { /// /// /// public class Log { /// /// 获得/设置 操作日志主键ID /// public string Id { get; set; } /// /// 获得/设置 操作类型 /// public string CRUD { get; set; } /// /// 获得/设置 用户名称 /// public string UserName { get; set; } /// /// 获得/设置 操作时间 /// public DateTime LogTime { get; set; } /// /// 获得/设置 客户端IP /// public string ClientIp { get; set; } /// /// 获取/设置 客户端信息 /// public string ClientAgent { get; set; } /// /// 获取/设置 请求网址 /// public string RequestUrl { get; set; } /// /// 查询所有日志信息 /// /// /// public virtual IEnumerable Retrieves() => DbManager.Create().Fetch("select * from Logs where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7)); /// /// 删除日志信息 /// /// /// private static void DeleteLogAsync() { System.Threading.Tasks.Task.Run(() => { var dtm = DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1)); DbManager.Create().Execute("delete from Logs where LogTime < @0", dtm); }); } /// /// 保存新增的日志信息 /// /// /// public virtual bool Save(Log p) { if (p == null) throw new ArgumentNullException(nameof(p)); DeleteLogAsync(); p.LogTime = DateTime.Now; DbManager.Create().Save(p); return true; } } }