增加功能:增加数据库错误日志记录功能
This commit is contained in:
parent
8e89d67e0c
commit
e6849053ea
|
@ -1,10 +1,12 @@
|
|||
using Bootstrap.Security.Filter;
|
||||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security.Filter;
|
||||
using Bootstrap.Security.Middleware;
|
||||
using Longbow.Cache;
|
||||
using Longbow.Cache.Middleware;
|
||||
using Longbow.Configuration;
|
||||
using Longbow.Data;
|
||||
using Longbow.Logging;
|
||||
using Longbow.Web;
|
||||
using Longbow.Web.WebSockets;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
@ -15,6 +17,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
|
||||
namespace Bootstrap.Admin
|
||||
|
@ -32,7 +35,7 @@ namespace Bootstrap.Admin
|
|||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddCors();
|
||||
services.AddLogging(builder => builder.AddFileLogger());
|
||||
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionHelper.Log));
|
||||
services.AddConfigurationManager();
|
||||
services.AddCacheManager();
|
||||
services.AddDBAccessFactory();
|
||||
|
@ -43,7 +46,7 @@ namespace Bootstrap.Admin
|
|||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||
options.Filters.Add<BootstrapAdminExceptionFilter>();
|
||||
options.Filters.Add<ExceptionFilter>();
|
||||
}).AddJsonOptions(options =>
|
||||
{
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
|
|
|
@ -24,9 +24,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="ex"></param>
|
||||
/// <param name="additionalInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Log(Exception ex, NameValueCollection additionalInfo)
|
||||
public static void Log(Exception ex, NameValueCollection additionalInfo)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
|
||||
|
@ -41,13 +40,11 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccessFactory.ToDBValue(ex.StackTrace)));
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception("Excetion Log Error", e);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询所有异常
|
||||
|
|
|
@ -33,8 +33,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
List<User> users = new List<User>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||
try
|
||||
{
|
||||
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -51,8 +50,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return users;
|
||||
});
|
||||
}
|
||||
|
@ -67,8 +64,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null order by RegisterTime desc";
|
||||
List<User> users = new List<User>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -83,8 +78,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return users;
|
||||
});
|
||||
}
|
||||
|
@ -95,8 +88,6 @@ namespace Bootstrap.DataAccess
|
|||
public static bool DeleteUser(IEnumerable<int> value)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteUsers"))
|
||||
{
|
||||
|
@ -105,11 +96,6 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
CacheCleanUtility.ClearCache(userIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -127,8 +113,6 @@ namespace Bootstrap.DataAccess
|
|||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||
}
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_SaveUsers"))
|
||||
{
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@id", p.Id));
|
||||
|
@ -146,11 +130,6 @@ namespace Bootstrap.DataAccess
|
|||
CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
ret = true;
|
||||
if (p.UserStatus == 1) NotificationHelper.MessagePool.Add(new MessageBody() { Category = "Users", Message = string.Format("{0}-{1}", p.UserName, p.Description) });
|
||||
}
|
||||
catch (DbException ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -167,8 +146,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -182,8 +159,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return users;
|
||||
}, RetrieveUsersByRoleIdDataKey);
|
||||
}
|
||||
|
@ -225,8 +200,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -245,8 +220,6 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId));
|
||||
try
|
||||
{
|
||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
@ -260,8 +233,6 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||
return users;
|
||||
}, RetrieveUsersByRoleIdDataKey);
|
||||
}
|
||||
|
@ -303,8 +274,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -318,8 +289,6 @@ namespace Bootstrap.DataAccess
|
|||
public static bool SaveUserIconByName(string userName, string iconName)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
string sql = "Update Users set Icon = @iconName where UserName = @userName";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
|
@ -330,11 +299,6 @@ namespace Bootstrap.DataAccess
|
|||
CacheCleanUtility.ClearCache(cacheKey: key);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -346,8 +310,6 @@ namespace Bootstrap.DataAccess
|
|||
public static bool SaveUserCssByName(string userName, string cssName)
|
||||
{
|
||||
bool ret = false;
|
||||
try
|
||||
{
|
||||
string sql = "Update Users set Css = @cssName where UserName = @userName";
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
|
@ -358,11 +320,6 @@ namespace Bootstrap.DataAccess
|
|||
CacheCleanUtility.ClearCache(cacheKey: key);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue