From 8ea2ef299548841bf687201c0d99a86278cf50dd Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Sat, 8 Sep 2018 17:20:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F=E5=8F=91=E7=94=9F=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=97=B6=E8=87=AA=E5=8A=A8=E6=8E=A8=E9=80=81=E5=88=B0?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/wwwroot/js/common-scripts.js | 8 ++++---- Bootstrap.DataAccess/ExceptionHelper.cs | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index 81b5d303..bfcef974 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -179,14 +179,14 @@ $(function () { var cate = result[index].Category; var msg = result[index].Message; switch (cate) { - case "Notification": - toastr.error(msg, "应用程序出现错误"); + case "DB": + toastr.error(msg, "数据库操作发生异常"); break; case "Users": toastr.success(msg, "新用户注册"); break; - case "Exception": - toastr.warning(msg, "程序发生异常"); + case "App": + toastr.warning(msg, "应用程序发生异常"); break; } } diff --git a/Bootstrap.DataAccess/ExceptionHelper.cs b/Bootstrap.DataAccess/ExceptionHelper.cs index 48b8a053..2af313a1 100644 --- a/Bootstrap.DataAccess/ExceptionHelper.cs +++ b/Bootstrap.DataAccess/ExceptionHelper.cs @@ -29,12 +29,12 @@ namespace Bootstrap.DataAccess /// public static void Log(Exception ex, NameValueCollection additionalInfo) { - if (additionalInfo["ErrorPage"] == null) return; + var errorPage = additionalInfo["ErrorPage"] ?? ex.Message.Substring(0, 50); var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())"; using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) { cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName)); - cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ErrorPage", DBAccessFactory.ToDBValue(additionalInfo["ErrorPage"]))); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ErrorPage", errorPage)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", DBAccessFactory.ToDBValue(additionalInfo["UserId"]))); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserIp", DBAccessFactory.ToDBValue(additionalInfo["UserIp"]))); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName)); @@ -42,8 +42,9 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace))); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); CacheManager.Clear(RetrieveExceptionsDataKey); - if (ex.GetType().IsSubclassOf(typeof(DbException))) - WebSocketServerManager.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new List { new { Category = "Notification", ex.Message } })))); + var category = "App"; + if (ex.GetType().IsSubclassOf(typeof(DbException))) category = "DB"; + WebSocketServerManager.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new MessageBody[] { new MessageBody() { Category = category, Message = ex.Message } })))); } } /// @@ -67,7 +68,7 @@ namespace Bootstrap.DataAccess { Id = (int)reader[0], AppDomainName = (string)reader[1], - ErrorPage = (string)reader[2], + ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], ExceptionType = (string)reader[5],