using System.Diagnostics; using DS.Module.Core.Log; using SqlSugar; namespace DS.WMS.Core { public static class LogExtensions { const long CONFIG_ID = 1288018625843826680; /// /// 将异常信息记录到数据库 /// /// /// /// 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(); } } }