增加功能:增加日志写入功能

This commit is contained in:
Argo-MacBookPro 2018-10-31 17:40:40 +08:00
parent e681580d2d
commit ce76c59aa6
1 changed files with 25 additions and 0 deletions

View File

@ -1,6 +1,7 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Bootstrap.DataAccess.MongoDB
{
@ -16,6 +17,7 @@ namespace Bootstrap.DataAccess.MongoDB
MongoDbAccessManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7));
});
}
/// <summary>
///
/// </summary>
@ -24,5 +26,28 @@ namespace Bootstrap.DataAccess.MongoDB
{
return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}
/// <summary>
///
/// </summary>
/// <param name="ex"></param>
/// <param name="additionalInfo"></param>
/// <returns></returns>
public override bool Log(Exception ex, NameValueCollection additionalInfo)
{
var excep = new Exceptions();
excep.Id = null;
excep.AppDomainName = AppDomain.CurrentDomain.FriendlyName;
excep.ErrorPage = additionalInfo?["ErrorPage"];
excep.ExceptionType = ex.GetType().FullName;
excep.LogTime = DateTime.Now;
excep.Message = ex.Message;
excep.StackTrace = ex.StackTrace;
excep.UserId = additionalInfo?["UserId"];
excep.UserIp = additionalInfo?["UserIp"];
MongoDbAccessManager.Exceptions.InsertOne(excep);
ClearExceptions();
return true;
}
}
}