From 26eeb8cab84f7ddd9fdf5c24bd3a5fa95dc6e0fb Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 16 Apr 2019 17:58:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9BUG=EF=BC=9A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF=E5=9C=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=BC=82=E5=B8=B8=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E4=B8=AD=E4=B8=8D=E6=98=BE=E7=A4=BA=20closed=20#IVGWL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Issue https://gitee.com/LongbowEnterprise/dashboard/issues?id=IVGWL --- .../Api/NotificationsController.cs | 4 ++-- Bootstrap.DataAccess/Exceptions.cs | 24 ++++++++++++++++--- DatabaseScripts/Install.sql | 1 + DatabaseScripts/MySQL/install.sql | 3 ++- DatabaseScripts/Postgresql/install.sql | 3 ++- DatabaseScripts/SQLite/Install.sql | 3 ++- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs index 0b85ce60..73bb5cd0 100644 --- a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs +++ b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs @@ -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); diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs index bd07f250..5703281c 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -3,7 +3,8 @@ using PetaPoco; using System; using System.Collections.Generic; using System.Collections.Specialized; - +using System.Data.Common; + namespace Bootstrap.DataAccess { /// @@ -61,6 +62,11 @@ namespace Bootstrap.DataAccess /// public string Period { get; set; } + /// + /// + /// + 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; diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql index 767c65ef..14789910 100644 --- a/DatabaseScripts/Install.sql +++ b/DatabaseScripts/Install.sql @@ -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 diff --git a/DatabaseScripts/MySQL/install.sql b/DatabaseScripts/MySQL/install.sql index d720af28..2423ed3d 100644 --- a/DatabaseScripts/MySQL/install.sql +++ b/DatabaseScripts/MySQL/install.sql @@ -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( diff --git a/DatabaseScripts/Postgresql/install.sql b/DatabaseScripts/Postgresql/install.sql index e7e75097..34276d44 100644 --- a/DatabaseScripts/Postgresql/install.sql +++ b/DatabaseScripts/Postgresql/install.sql @@ -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( diff --git a/DatabaseScripts/SQLite/Install.sql b/DatabaseScripts/SQLite/Install.sql index 1860a50c..d90a7b21 100644 --- a/DatabaseScripts/SQLite/Install.sql +++ b/DatabaseScripts/SQLite/Install.sql @@ -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(