BillLogService.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using wms.sqlsugar.model.fj;
  9. using WMS.BZSqlSugar;
  10. using WMS.Info;
  11. using WMS.Util;
  12. namespace WMS.BZServices.FJ
  13. {
  14. public class BillLogService
  15. {
  16. private readonly Repository<BillLog> _billLogRepository;
  17. public BillLogService(Repository<BillLog> billLogRepository)
  18. {
  19. _billLogRepository = billLogRepository;
  20. }
  21. public void WriteLog(BZBLLExecInfo BLLExec, ELogType eLogType)
  22. {
  23. try
  24. {
  25. BillLog log = new BillLog();
  26. log.RunMs = (int)CommonUtil.TimerEnd(BLLExec.RunWatch);
  27. log.LogTime = DateTime.Now;
  28. log.AppTypeNum = 0;
  29. log.TypeNum = (int)eLogType;
  30. if (BLLExec.Ex == null)
  31. {
  32. log.ContentText = string.IsNullOrWhiteSpace(BLLExec.BLLObj.SuccessMsg) ? "操作成功。" : BLLExec.BLLObj.SuccessMsg;
  33. log.IsSucc = 1;
  34. }
  35. else
  36. {
  37. log.ContentText = BLLExec.Ex.Message;
  38. log.IsSucc = 0;
  39. }
  40. if (BLLExec.BLLObj != null)
  41. {
  42. log.AppTypeNum = (int)BLLExec.BLLObj.LoginUser.AppType;
  43. log.Method = BZBLLCore.GetBLLClassNo(BLLExec.BLLObj);
  44. log.MethodText = BLLExec.BLLObj.BLLDesc;
  45. StringBuilder sb = new StringBuilder();
  46. sb.Append("---------------------------------------请求数据-----------------------------------------------------------------");
  47. sb.AppendLine(BLLExec.BLLObj.InJsonData);
  48. if (BLLExec.Ex != null)
  49. {
  50. sb.AppendLine("----------------------------------------异常数据----------------------------------------------------------------");
  51. sb.AppendLine(BLLExec.Ex.ToString());
  52. sb.AppendLine("----------------------------------------异常内部数据----------------------------------------------------------------");
  53. if (BLLExec.Ex.InnerException == null)
  54. {
  55. sb.AppendLine(string.Format("Message:{0} Source:{1} StackTrace:{2} ", BLLExec.Ex.Message, BLLExec.Ex.Source, BLLExec.Ex.StackTrace));
  56. }
  57. else
  58. {
  59. sb.AppendLine(string.Format("Message:{0} Source:{1} StackTrace:{2} ", BLLExec.Ex.InnerException.Message, BLLExec.Ex.InnerException.Source, BLLExec.Ex.InnerException.StackTrace));
  60. }
  61. }
  62. log.ParamJson = sb.ToString();
  63. log.Ip = BLLExec.BLLObj.LoginUser.IPAddress;
  64. log.LogWho = BLLExec.BLLObj.LoginUser.UserNo;
  65. //log. = BLLExec.BLLObj.LoginUser.AppDeviceNo;
  66. }
  67. _billLogRepository.Insert(log);
  68. }
  69. catch (Exception ex)
  70. {
  71. LogFactory.GetLogger("WMS.Core.SysLogCore.WriteLog").Error(ex.ToString());
  72. }
  73. }
  74. public void WriteLog(LoginUserInfo LoginUser, dynamic JsonData, string ContentText, string ClassNo, string ClassDesc, Stopwatch ts, ELogType eLogType, Exception ex = null)
  75. {
  76. try
  77. {
  78. string injson = JsonData == null ? "" : JsonConvert.SerializeObject(JsonData);
  79. BillLog log = new BillLog();
  80. log.RunMs = (int)CommonUtil.TimerEnd(ts);
  81. log.LogTime = DateTime.Now;
  82. log.AppTypeNum = (int)LoginUser.AppType;
  83. log.TypeNum = (int)eLogType;
  84. if (!string.IsNullOrWhiteSpace(ContentText))
  85. {
  86. log.ContentText = ContentText;
  87. }
  88. else
  89. {
  90. log.ContentText = ex == null ? "操作成功。" : ex.Message;
  91. }
  92. log.IsSucc = ex == null ? 1 : 0;
  93. log.Ip = LoginUser.IPAddress;
  94. log.Method = ClassNo;
  95. log.MethodText = ClassDesc;
  96. //log.F_APPDEVICENO = LoginUser.AppDeviceNo;
  97. log.LogWho = LoginUser.UserNo;
  98. log.AddWho = LoginUser.UserNo;
  99. log.AddTime = DateTime.Now;
  100. log.EditTime = DateTime.Now;
  101. log.EditWho = LoginUser.UserNo;
  102. log.ParamJson = injson;
  103. _billLogRepository.Insert(log);
  104. }
  105. catch (Exception e)
  106. {
  107. CommonUtil.TimerEnd(ts);
  108. LogFactory.GetLogger("WMS.BZServices.PT.BillLogService.WriteLog").Error(e.ToString());
  109. }
  110. }
  111. }
  112. }