2018-10-30 13:07:29 +08:00
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-10-31 17:40:40 +08:00
|
|
|
|
using System.Collections.Specialized;
|
2018-10-30 13:07:29 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess.MongoDB
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Exceptions : DataAccess.Exceptions
|
|
|
|
|
{
|
2018-10-30 22:15:29 +08:00
|
|
|
|
private static void ClearExceptions()
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Tasks.Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
MongoDbAccessManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-10-31 17:40:40 +08:00
|
|
|
|
|
2018-10-30 13:07:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override IEnumerable<DataAccess.Exceptions> RetrieveExceptions()
|
|
|
|
|
{
|
2018-10-30 22:15:29 +08:00
|
|
|
|
return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
|
2018-10-30 13:07:29 +08:00
|
|
|
|
}
|
2018-10-31 17:40:40 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ex"></param>
|
|
|
|
|
/// <param name="additionalInfo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override bool Log(Exception ex, NameValueCollection additionalInfo)
|
|
|
|
|
{
|
2018-10-31 21:29:42 +08:00
|
|
|
|
var excep = new DataAccess.Exceptions
|
|
|
|
|
{
|
|
|
|
|
Id = null,
|
|
|
|
|
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
|
2018-11-01 10:44:19 +08:00
|
|
|
|
ErrorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name),
|
2018-10-31 21:29:42 +08:00
|
|
|
|
ExceptionType = ex.GetType().FullName,
|
|
|
|
|
LogTime = DateTime.Now,
|
|
|
|
|
Message = ex.Message,
|
|
|
|
|
StackTrace = ex.StackTrace,
|
|
|
|
|
UserId = additionalInfo?["UserId"],
|
|
|
|
|
UserIp = additionalInfo?["UserIp"]
|
|
|
|
|
};
|
2018-10-31 17:40:40 +08:00
|
|
|
|
MongoDbAccessManager.Exceptions.InsertOne(excep);
|
|
|
|
|
ClearExceptions();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-10-30 13:07:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|