12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using Library;
- using LitJson;
- using MySystem;
- public class LogHelper
- {
- public readonly static LogHelper Instance = new LogHelper();
- private LogHelper()
- { }
- string[] BlackList = { "服务商平台查询申请单状态API", "服务商平台查询分账结果API", "查询签约申请的结果", "支付宝查询分账结果" };
- public void WriteLog(string Content, string FileName, string BrandId = "0")
- {
- if(BlackList.Contains(FileName))
- {
- string key = function.MD532(Content + FileName);
- if(!string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>(key)))
- {
- return;
- }
- RedisDbconn.Instance.Set(key, "1");
- RedisDbconn.Instance.SetExpire(key, 3600);
- }
- function.WriteLog(Content, FileName);
- // Dictionary<string, string> dic = new Dictionary<string, string>();
- // dic.Add("Topic", FileName);
- // dic.Add("Content", Content);
- // dic.Add("BrandId", BrandId);
- // RedisDbconn.Instance.AddList("LogQueue", Newtonsoft.Json.JsonConvert.SerializeObject(dic));
- }
- public void Start()
- {
- Thread th = new Thread(DoWorks);
- th.IsBackground = true;
- th.Start();
- }
- public void DoWorks()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("LogQueue");
- if (!string.IsNullOrEmpty(content))
- {
- try
- {
- DoQueue(content);
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "SLS日志异常");
- }
- }
- else
- {
- Thread.Sleep(5000);
- }
- }
- }
- public void DoQueue(string content)
- {
- // JsonData JsonObj = JsonMapper.ToObject(content);
- // string Topic = JsonObj["Topic"].ToString();
- // string Cont = JsonObj["Content"].ToString();
- // string BrandId = JsonObj["BrandId"].ToString();
- // SLS.WriteLog(DateTime.Now, Topic, Cont, new Dictionary<string, string>()
- // {
- // {"BrandId", BrandId}
- // });
- }
- }
|