LogHelper.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading;
  6. using Library;
  7. using LitJson;
  8. using MySystem;
  9. public class LogHelper
  10. {
  11. public readonly static LogHelper Instance = new LogHelper();
  12. private LogHelper()
  13. { }
  14. string[] BlackList = { "好哒查询商户审核状态", "好哒查询实名认证状态", "好哒分账交易详情查询", "间连商户开户意愿确认(提交申请单)查询申请单状态-请求参数", "查询支付宝商家认证申请单状态", "查询支付宝商户意愿申请状态", "获取微信商户开户意愿确认状态", "获取支付宝商家认证状态" };
  15. public void WriteLog(string Content, string FileName, string BrandId = "0")
  16. {
  17. if(BlackList.Contains(FileName) && Library.ConfigurationManager.EnvironmentFlag == 2)
  18. {
  19. string key = function.MD532(Content + FileName);
  20. if(!string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>(key)))
  21. {
  22. return;
  23. }
  24. RedisDbconn.Instance.Set(key, "1");
  25. RedisDbconn.Instance.SetExpire(key, 600);
  26. }
  27. function.WriteLog(Content, FileName);
  28. // Dictionary<string, string> dic = new Dictionary<string, string>();
  29. // dic.Add("Topic", FileName);
  30. // dic.Add("Content", Content);
  31. // dic.Add("BrandId", BrandId);
  32. // RedisDbconn.Instance.AddList("LogQueue", Newtonsoft.Json.JsonConvert.SerializeObject(dic));
  33. }
  34. public void Start()
  35. {
  36. Thread th = new Thread(DoWorks);
  37. th.IsBackground = true;
  38. th.Start();
  39. }
  40. public void DoWorks()
  41. {
  42. while (true)
  43. {
  44. string content = RedisDbconn.Instance.RPop<string>("LogQueue");
  45. if (!string.IsNullOrEmpty(content))
  46. {
  47. try
  48. {
  49. DoQueue(content);
  50. }
  51. catch (Exception ex)
  52. {
  53. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "SLS日志异常");
  54. }
  55. }
  56. else
  57. {
  58. Thread.Sleep(5000);
  59. }
  60. }
  61. }
  62. public void DoQueue(string content)
  63. {
  64. // JsonData JsonObj = JsonMapper.ToObject(content);
  65. // string Topic = JsonObj["Topic"].ToString();
  66. // string Cont = JsonObj["Content"].ToString();
  67. // string BrandId = JsonObj["BrandId"].ToString();
  68. // SLS.WriteLog(DateTime.Now, Topic, Cont, new Dictionary<string, string>()
  69. // {
  70. // {"BrandId", BrandId}
  71. // });
  72. }
  73. }