修改BUG:数据库异常信息在数据库异常通知中不显示 closed #IVGWL

#Issue
https://gitee.com/LongbowEnterprise/dashboard/issues?id=IVGWL
This commit is contained in:
Argo Zhang 2019-04-16 17:58:46 +08:00
parent 80f27b5cf3
commit 26eeb8cab8
6 changed files with 30 additions and 8 deletions

View File

@ -47,7 +47,7 @@ namespace Bootstrap.Admin.Controllers.Api
message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon));
//Apps
var apps = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException");
var apps = ExceptionsHelper.Retrieves().Where(n => n.Category != "DB");
var appExceptionsCount = apps.Count();
apps = apps.Take(6);
@ -62,7 +62,7 @@ namespace Bootstrap.Admin.Controllers.Api
});
//Dbs
var dbs = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException");
var dbs = ExceptionsHelper.Retrieves().Where(n => n.Category == "DB");
var dbExceptionsCount = dbs.Count();
dbs = dbs.Take(6);

View File

@ -3,7 +3,8 @@ using PetaPoco;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.Common;
namespace Bootstrap.DataAccess
{
/// <summary>
@ -61,6 +62,11 @@ namespace Bootstrap.DataAccess
/// </summary>
public string Period { get; set; }
/// <summary>
///
/// </summary>
public string Category { get; set; }
private static void ClearExceptions() => System.Threading.Tasks.Task.Run(() =>
{
DbManager.Create().Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
@ -76,7 +82,18 @@ namespace Bootstrap.DataAccess
{
if (ex == null) return true;
var errorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
var errorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
var loopEx = ex;
var category = "App";
while (loopEx != null)
{
if (typeof(DbException).IsAssignableFrom(loopEx.GetType()))
{
category = "DB";
break;
}
loopEx = loopEx.InnerException;
}
DbManager.Create().Insert(new Exceptions
{
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
@ -86,7 +103,8 @@ namespace Bootstrap.DataAccess
ExceptionType = ex.GetType().FullName,
Message = ex.Message,
StackTrace = ex.StackTrace,
LogTime = DateTime.Now
LogTime = DateTime.Now,
Category = category
});
ClearExceptions();
return true;

View File

@ -324,6 +324,7 @@ CREATE TABLE [dbo].[Exceptions](
[Message] [nvarchar](max) NOT NULL,
[StackTrace] [nvarchar](max) NULL,
[LogTime] [datetime] NOT NULL,
[Category] [varchar](50) NULL,
CONSTRAINT [PK_Exceptions] PRIMARY KEY CLUSTERED
(
[ID] ASC

View File

@ -105,7 +105,8 @@ CREATE TABLE Exceptions(
ExceptionType TEXT NOT NULL,
Message TEXT NOT NULL,
StackTrace TEXT NULL,
LogTime DATETIME NOT NULL
LogTime DATETIME NOT NULL,
Category VARCHAR (50) NULL
);
CREATE TABLE Dicts(

View File

@ -105,7 +105,8 @@ CREATE TABLE Exceptions(
ExceptionType TEXT NOT NULL,
Message TEXT NOT NULL,
StackTrace TEXT NULL,
LogTime DATE NOT NULL
LogTime DATE NOT NULL,
Category VARCHAR (50) NULL
);
CREATE TABLE Dicts(

View File

@ -105,7 +105,8 @@ CREATE TABLE Exceptions(
ExceptionType TEXT NOT NULL,
Message TEXT NOT NULL,
StackTrace TEXT NULL,
LogTime DATETIME NOT NULL
LogTime DATETIME NOT NULL,
Category VARCHAR (50) NULL
);
CREATE TABLE Dicts(