diff --git a/Bootstrap.DataAccess.MongoDB/Exceptions.cs b/Bootstrap.DataAccess.MongoDB/Exceptions.cs
index 0efa19dd..6cfbf64f 100644
--- a/Bootstrap.DataAccess.MongoDB/Exceptions.cs
+++ b/Bootstrap.DataAccess.MongoDB/Exceptions.cs
@@ -9,14 +9,20 @@ namespace Bootstrap.DataAccess.MongoDB
///
public class Exceptions : DataAccess.Exceptions
{
+ private static void ClearExceptions()
+ {
+ System.Threading.Tasks.Task.Run(() =>
+ {
+ MongoDbAccessManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
+ });
+ }
///
///
///
///
public override IEnumerable RetrieveExceptions()
{
- var msg = MongoDbAccessManager.DBAccess.GetCollection("Exceptions");
- return msg.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
+ return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}
}
}
diff --git a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs
index 04b136f6..7bd270f4 100644
--- a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs
+++ b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs
@@ -49,6 +49,16 @@ namespace Bootstrap.DataAccess.MongoDB
///
///
///
+ public static IMongoCollection Exceptions
+ {
+ get
+ {
+ return DBAccess.GetCollection("Exceptions");
+ }
+ }
+ ///
+ ///
+ ///
public static IMongoCollection Users
{
get
diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs
index 92208f00..ffeab6fe 100644
--- a/Bootstrap.DataAccess.SQLite/Exceptions.cs
+++ b/Bootstrap.DataAccess.SQLite/Exceptions.cs
@@ -1,5 +1,4 @@
using Longbow;
-using Longbow.Cache;
using Longbow.Configuration;
using Longbow.Data;
using System;
@@ -33,7 +32,7 @@ namespace Bootstrap.DataAccess.SQLite
///
///
///
- public override void Log(Exception ex, NameValueCollection additionalInfo)
+ public override bool Log(Exception ex, NameValueCollection additionalInfo)
{
if (additionalInfo == null)
{
@@ -56,9 +55,9 @@ namespace Bootstrap.DataAccess.SQLite
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
- CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey);
ClearExceptions();
}
+ return true;
}
///
/// 查询一周内所有异常
diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs
index b43703df..fa377050 100644
--- a/Bootstrap.DataAccess/Exceptions.cs
+++ b/Bootstrap.DataAccess/Exceptions.cs
@@ -1,5 +1,4 @@
-using Longbow.Cache;
-using Longbow.Configuration;
+using Longbow.Configuration;
using Longbow.Data;
using System;
using System.Collections.Generic;
@@ -70,7 +69,7 @@ namespace Bootstrap.DataAccess
///
///
///
- public virtual void Log(Exception ex, NameValueCollection additionalInfo)
+ public virtual bool Log(Exception ex, NameValueCollection additionalInfo)
{
if (additionalInfo == null)
{
@@ -93,9 +92,9 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
- CacheManager.Clear(ExceptionsHelper.RetrieveExceptionsDataKey);
ClearExceptions();
}
+ return true;
}
///
/// 查询一周内所有异常
diff --git a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
index 85e7ec3e..833e2da2 100644
--- a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
+++ b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs
@@ -21,7 +21,12 @@ namespace Bootstrap.DataAccess
///
///
///
- public static void Log(Exception ex, NameValueCollection additionalInfo) => DbAdapterManager.Create().Log(ex, additionalInfo);
+ public static void Log(Exception ex, NameValueCollection additionalInfo)
+ {
+ var ret = DbAdapterManager.Create().Log(ex, additionalInfo);
+ if (ret) CacheManager.Clear(RetrieveExceptionsDataKey);
+ }
+
///
/// 查询一周内所有异常
///