添加日志
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using CommonEntity;
|
||||
using CSRedis;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace BLWLogProduce.Models
|
||||
@@ -7,7 +10,9 @@ namespace BLWLogProduce.Models
|
||||
public class MyPublishRedis
|
||||
{
|
||||
public static CSRedisClient? redis4;
|
||||
public static CSRedisClient? redis6;
|
||||
|
||||
public static Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private const string ip = "127.0.0.1";
|
||||
private const string port = "6379";
|
||||
static MyPublishRedis()
|
||||
@@ -16,28 +21,30 @@ namespace BLWLogProduce.Models
|
||||
if (!string.IsNullOrEmpty(redisHostStr))
|
||||
{
|
||||
redis4 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=4");
|
||||
string channel = "__keyevent@4__:expired";
|
||||
redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6");
|
||||
string channel = "__keyevent@6__:expired";
|
||||
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
|
||||
{
|
||||
string data = msg.Body;
|
||||
try
|
||||
{
|
||||
var o = JsonSerializer.Deserialize<OnOffLineData>(msg.Body);
|
||||
o.CurrentStatus = "off";
|
||||
string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
||||
var data_take =redis4.Get(data);
|
||||
if (!string.IsNullOrEmpty(data_take))
|
||||
{
|
||||
var o = JsonConvert.DeserializeObject<OnOffLineData>(data_take);
|
||||
o.CurrentStatus = "off";
|
||||
string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
|
||||
|
||||
redis4.Publish("redis-on_off_line", str);
|
||||
redis6.Publish("redis-on_off_line", str);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("定阅出错:"+data);
|
||||
}
|
||||
});
|
||||
redis4.Subscribe(QQQ);
|
||||
redis6.Subscribe(QQQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MyPublishRedis2
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user