添加日志

This commit is contained in:
2026-02-04 18:06:18 +08:00
parent 3de5990573
commit b9ef94a671
28 changed files with 134 additions and 54 deletions

View File

@@ -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
{
}
}

View File

@@ -548,6 +548,10 @@ namespace BLWLogProduce.Services
{
return;
}
if (poo.cmd_word.Equals("0E")&&poo.fault_list.Count==0&&poo.device_list.Count==0)
{
return;
}
string TopicKey1 = KafkaKey.BLWLog4NodeJs_RCU_Action_Topic;
string DetailKey1 = poo.frame_id.ToString();
@@ -662,6 +666,7 @@ namespace BLWLogProduce.Services
try
{
MyPublishRedis.redis6.Set("ChangLiang", "1", 3600); //设置过期时间1小时离线事件靠过期事件触发
string body = args.Body;
CommonEntity.OnOffLineData? usa = System.Text.Json.JsonSerializer.Deserialize<CommonEntity.OnOffLineData>(body);
@@ -678,6 +683,7 @@ namespace BLWLogProduce.Services
return;
}
string Key1 = KafkaKey.BLWLog4NodeJs_RCU_OnOffLine_Topic;
string Key2 = usa.HostNumber;
byte[] nnn = Encoding.UTF8.GetBytes(body);
@@ -790,9 +796,26 @@ namespace BLWLogProduce.Services
{
string body = args.Body;
NewVersionHexData? usa = System.Text.Json.JsonSerializer.Deserialize<NewVersionHexData>(body);
byte[] bytes = MyMessagePacker.FastSerialize(usa);
string TopicKey = KafkaKey.BLWLog_RCU_Topic;
string DetailKey = KafkaKey.RCUNewVersion_RestartReason;
RestartIOTData rrr = new RestartIOTData()
{
HotelCode = usa.HotelCode,
HostNumber = usa.HostNumber,
MAC = usa.MAC,
RoomNumber = usa.RoomNumber,
EndPoint = usa.RemoteEndPoint,
CurrentStatus = usa.CurrentStatus,
CurrentTime = usa.CurrentTime,
UnixTime = Tools.GetUnixTime_MS(),
LauncherVersion= usa.LauncherVersion,
RebootReason= usa.RebootReason
};
byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rrr));
//byte[] bytes = MyMessagePacker.FastSerialize(rrr);
string TopicKey = KafkaKey.BLWLog4NodeJs_RCU_OnOffLine_Topic;
string DetailKey = usa.HotelCode;
var dr = await p.ProduceAsync(TopicKey, new Message<string, byte[]> { Key = DetailKey, Value = bytes });
}
catch (Exception ex)
@@ -956,6 +979,7 @@ namespace BLWLogProduce.Services
//新版本日志
CSRedisCacheHelper.redis3.Subscribe(TSLog_DingYue);
CSRedisCacheHelper.redis3.Subscribe(TSLog_DingYue_0X36);
CSRedisCacheHelper.redis3.Subscribe(DingYue11);
}
catch (Exception ex)
{

View File

@@ -396,19 +396,19 @@ namespace BLWLogServer.Services
else if (k.Equals(KafkaKey.RCUNewVersion_RestartReason))
{
var collection = client.GetDatabase("udppackage").GetCollection<NewVersionHexData_db>("rcu_hexdata");
NewVersionHexData UDPPPP = MyMessagePacker.FastDeserialize<NewVersionHexData>(v);
NewVersionHexData_db cv = new NewVersionHexData_db();
cv.HotelCode = UDPPPP.HotelCode;
cv.HostNumber = UDPPPP.HostNumber;
cv.RoomNumber = UDPPPP.RoomNumber;
cv.CurrentTime = UDPPPP.CurrentTime;
cv.RemoteEndPoint = UDPPPP.RemoteEndPoint;
cv.CmdType = UDPPPP.CmdType;
cv.HexData = UDPPPP.HexData;
cv.CurrentTime = UDPPPP.CurrentTime;
//var collection = client.GetDatabase("udppackage").GetCollection<NewVersionHexData_db>("rcu_hexdata");
//NewVersionHexData UDPPPP = MyMessagePacker.FastDeserialize<NewVersionHexData>(v);
//NewVersionHexData_db cv = new NewVersionHexData_db();
//cv.HotelCode = UDPPPP.HotelCode;
//cv.HostNumber = UDPPPP.HostNumber;
//cv.RoomNumber = UDPPPP.RoomNumber;
//cv.CurrentTime = UDPPPP.CurrentTime;
//cv.RemoteEndPoint = UDPPPP.RemoteEndPoint;
//cv.CmdType = UDPPPP.CmdType;
//cv.HexData = UDPPPP.HexData;
//cv.CurrentTime = UDPPPP.CurrentTime;
await collection.InsertOneAsync(cv);
//await collection.InsertOneAsync(cv);
}
else if (k.Equals(KafkaKey.RCUNewVersion_0E))
{
@@ -476,9 +476,10 @@ namespace BLWLogServer.Services
}
}
}
catch (OperationCanceledException)
catch (OperationCanceledException ex)
{
logger.Error("操作出错");
logger.Error("操作出错"+ex.Message);
logger.Error(ex.StackTrace);
Console.WriteLine("操作错误");
}
catch (Exception ex)

View File

@@ -72,6 +72,12 @@ namespace CommonEntity
public string? DeviceAddress { get; set; }
}
public class RestartIOTData:OnOffLineData
{
public byte[]? LauncherVersion { get; set; }
public byte[]? RebootReason { get; set; }
}
[GenerateSerializer()]
[MessagePackObject()]
public class OnOffLineData

View File

@@ -31,6 +31,21 @@ namespace CommonEntity
[Key(6)]
public DateTime CurrentTime { get; set; }
[Key(7)]
public string? MAC { get; set; }
[Key(8)]
public string? CurrentStatus { get; set; }
[Key(9)]
public long? UnixTime { get; set; }
[Key(10)]
public byte[]? LauncherVersion { get; set; }
[Key(11)]
public byte[]? RebootReason { get; set; }
}

View File

@@ -35,7 +35,7 @@ namespace CommonEntity
/// 心跳包
/// </summary>
public static string BLWLog4NodeJs_RCU_Topic = "blwlog4Nodejs-rcu-heartbeat-topic";
public static string BLWLog4NodeJs_RCU_OnOffLine_Topic = "blwlog4Nodejs-rcu-onoffline-topic";
public static string BLWLog4NodeJs_RCU_OnOffLine_Topic = "blwlog4Nodejs-rcu-onoffline-topic-0";
public static string BLWLog4NodeJs_RCU_Action_Topic = "blwlog4Nodejs-rcu-action-topic";
#endregion

View File

@@ -39,34 +39,15 @@ namespace Common
string channel = "__keyevent@4__:expired";
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
{
//string Key = CacheKey.UPGradeProgressBar + "_" + id;
try
{
if (!msg.Body.StartsWith("hb#"))
{
bool containsHyphen = msg.Body.Contains("-");
bool isNumeric = msg.Body.All(char.IsDigit);
if (containsHyphen == false && isNumeric)
{
//string hotelcode = Tools.HostNumberToHotelCode(msg.Body).ToString();
//OnOffLineData o = new OnOffLineData();
//o.HotelCode = hotelcode;
//o.HostNumber = msg.Body;
//o.CurrentStatus = "off";
//o.CurrentTime = DateTime.Now;
////新来的数据
//string str = Newtonsoft.Json.JsonConvert.SerializeObject(o);
//CSRedisCacheHelper.redis3.Publish("redis-on_off_line", str);
//redis4.Set(HeartBeatPrefix + "_" + msg.Body, 1, 5 * 60);
}
}
}
catch (Exception ex)
{
}
});
redis.Subscribe(QQQ);
//redis.Subscribe(QQQ);
}
}
/// <summary>

40
ConsoleApp2/GoodRedis.cs Normal file
View File

@@ -0,0 +1,40 @@
using CSRedis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
public class GoodRedis
{
public static CSRedisClient? redis6;
private const string ip = "127.0.0.1";
private const string port = "6379";
static GoodRedis()
{
var redisHostStr = string.Format("{0}:{1}", ip, port);
if (!string.IsNullOrEmpty(redisHostStr))
{
redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6");
//string channel = "__keyevent@6__:expired";
string channel = "__keyevent@6__:expired";
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
{
//body 是键
string data = msg.Body;
try
{
Console.WriteLine(data);
}
catch (Exception ex)
{
}
});
redis6.Subscribe(QQQ);
}
}
}
}

View File

@@ -5,6 +5,7 @@ using BLWData.Entity;
using CommonEntity;
using CommonTools;
using MessagePack;
using Newtonsoft.Json;
namespace ConsoleApp2
{
@@ -13,6 +14,10 @@ namespace ConsoleApp2
static void Main(string[] args)
{
GoodRedis.redis6.Set("aaa", "bbb", 10);
Console.ReadLine();
string YYY111111 = File.ReadAllText("2.txt");
var o = JsonConvert.DeserializeObject<CommonEntity.OnOffLineData>(YYY111111);
string afds = "hello";
string dda = afds;
dda = "world";
@@ -52,7 +57,7 @@ namespace ConsoleApp2
string HOSTNUMBER = "099008" + MAC1 + MAC2;
string nnn = File.ReadAllText("1.txt");
UDPPackage? usa = JsonSerializer.Deserialize<UDPPackage>(nnn);
UDPPackage? usa = System.Text.Json.JsonSerializer.Deserialize<UDPPackage>(nnn);
AAA a = new AAA();
MyClass mm = new MyClass();
mm.Age = 30;

View File

@@ -17,6 +17,7 @@ namespace Redis定阅
NengHao? poo = System.Text.Json.JsonSerializer.Deserialize<NengHao>(body);
}));
CSRedisCacheHelper.redis.Subscribe(DingYue3);
Console.ReadLine();
}
}
}

View File

@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+10bf712006c48a55355558d20b38cacc42f7879c")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3de5990573473ba6dad2b9f61b1d597740cd6ff2")]
[assembly: System.Reflection.AssemblyProductAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyTitleAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
5283559792cfb48abbd55d29822fde595259debf0e2dbd5145d5bb9737d31a98
cffca3bad22d59989963e58ffa867bb7a20c1d17663478a4cf724d50f06891d2

View File

@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+10bf712006c48a55355558d20b38cacc42f7879c")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3de5990573473ba6dad2b9f61b1d597740cd6ff2")]
[assembly: System.Reflection.AssemblyProductAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyTitleAttribute("Redis定阅")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
99d430bebbce6c50f252c7cf5891f373a780ce938fba0ebed0f195265e8a331a
6b5070cb382d125c9ffb0bb5415855e4173eae9cf2c6bd156d0b4a3335889da7