using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using wms.sqlsugar.model.fj; using WMS.BZSqlSugar; using WMS.Info; using WMS.Util; namespace WMS.BZServices.FJ { public class BillLogService { private readonly Repository _billLogRepository; public BillLogService(Repository billLogRepository) { _billLogRepository = billLogRepository; } public void WriteLog(BZBLLExecInfo BLLExec, ELogType eLogType) { try { BillLog log = new BillLog(); log.RunMs = (int)CommonUtil.TimerEnd(BLLExec.RunWatch); log.LogTime = DateTime.Now; log.AppTypeNum = 0; log.TypeNum = (int)eLogType; if (BLLExec.Ex == null) { log.ContentText = string.IsNullOrWhiteSpace(BLLExec.BLLObj.SuccessMsg) ? "操作成功。" : BLLExec.BLLObj.SuccessMsg; log.IsSucc = 1; } else { log.ContentText = BLLExec.Ex.Message; log.IsSucc = 0; } if (BLLExec.BLLObj != null) { log.AppTypeNum = (int)BLLExec.BLLObj.LoginUser.AppType; log.Method = BZBLLCore.GetBLLClassNo(BLLExec.BLLObj); log.MethodText = BLLExec.BLLObj.BLLDesc; StringBuilder sb = new StringBuilder(); sb.Append("---------------------------------------请求数据-----------------------------------------------------------------"); sb.AppendLine(BLLExec.BLLObj.InJsonData); if (BLLExec.Ex != null) { sb.AppendLine("----------------------------------------异常数据----------------------------------------------------------------"); sb.AppendLine(BLLExec.Ex.ToString()); sb.AppendLine("----------------------------------------异常内部数据----------------------------------------------------------------"); if (BLLExec.Ex.InnerException == null) { sb.AppendLine(string.Format("Message:{0} Source:{1} StackTrace:{2} ", BLLExec.Ex.Message, BLLExec.Ex.Source, BLLExec.Ex.StackTrace)); } else { sb.AppendLine(string.Format("Message:{0} Source:{1} StackTrace:{2} ", BLLExec.Ex.InnerException.Message, BLLExec.Ex.InnerException.Source, BLLExec.Ex.InnerException.StackTrace)); } } log.ParamJson = sb.ToString(); log.Ip = BLLExec.BLLObj.LoginUser.IPAddress; log.LogWho = BLLExec.BLLObj.LoginUser.UserNo; //log. = BLLExec.BLLObj.LoginUser.AppDeviceNo; } _billLogRepository.Insert(log); } catch (Exception ex) { LogFactory.GetLogger("WMS.Core.SysLogCore.WriteLog").Error(ex.ToString()); } } public void WriteLog(LoginUserInfo LoginUser, dynamic JsonData, string ContentText, string ClassNo, string ClassDesc, Stopwatch ts, ELogType eLogType, Exception ex = null) { try { string injson = JsonData == null ? "" : JsonConvert.SerializeObject(JsonData); BillLog log = new BillLog(); log.RunMs = (int)CommonUtil.TimerEnd(ts); log.LogTime = DateTime.Now; log.AppTypeNum = (int)LoginUser.AppType; log.TypeNum = (int)eLogType; if (!string.IsNullOrWhiteSpace(ContentText)) { log.ContentText = ContentText; } else { log.ContentText = ex == null ? "操作成功。" : ex.Message; } log.IsSucc = ex == null ? 1 : 0; log.Ip = LoginUser.IPAddress; log.Method = ClassNo; log.MethodText = ClassDesc; //log.F_APPDEVICENO = LoginUser.AppDeviceNo; log.LogWho = LoginUser.UserNo; log.AddWho = LoginUser.UserNo; log.AddTime = DateTime.Now; log.EditTime = DateTime.Now; log.EditWho = LoginUser.UserNo; log.ParamJson = injson; _billLogRepository.Insert(log); } catch (Exception e) { CommonUtil.TimerEnd(ts); LogFactory.GetLogger("WMS.BZServices.PT.BillLogService.WriteLog").Error(e.ToString()); } } } }