You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using DS.Module.Core.Log;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core
|
|
|
|
|
{
|
|
|
|
|
public static class LogExtensions
|
|
|
|
|
{
|
|
|
|
|
const long CONFIG_ID = 1288018625843826680;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将异常信息记录到数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ex"></param>
|
|
|
|
|
/// <param name="db"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task LogAsync(this Exception ex, ISqlSugarClient db)
|
|
|
|
|
{
|
|
|
|
|
string className = string.Empty;
|
|
|
|
|
var stacktrace = new StackTrace();
|
|
|
|
|
if (stacktrace.FrameCount >= 0)
|
|
|
|
|
className = stacktrace.GetFrame(0).GetMethod().DeclaringType.Name;
|
|
|
|
|
|
|
|
|
|
var exLog = new SysLogException()
|
|
|
|
|
{
|
|
|
|
|
ClassName = className,
|
|
|
|
|
ExceptionName = ex.GetType().FullName,
|
|
|
|
|
ExceptionMsg = ex.Message,
|
|
|
|
|
ExceptionSource = ex.Source,
|
|
|
|
|
StackTrace = ex.StackTrace,
|
|
|
|
|
ParamsObj = ex.TargetSite.GetParameters().ToString(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var scope = (SqlSugarScope)db;
|
|
|
|
|
await scope.GetConnection(CONFIG_ID).Insertable(exLog).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|