初始化

This commit is contained in:
2025-11-20 16:20:04 +08:00
commit 4230fa4d27
777 changed files with 232488 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using CSRedis;
using LogCap.Common;
using System.Threading.Tasks;
namespace Common
{
/// <summary>
/// Redis缓存辅助类
/// </summary>
public class CSRedisCacheHelper
{
public static CSRedisClient redis;
private static int SessionExpireMinutes = int.Parse(ReadConfig.Instance.get_session_expire_minutes);
//private static int RedisMaxReadPool = int.Parse(ConfigurationManager.AppSettings["redis_max_read_pool"]);
//private static int RedisMaxWritePool = int.Parse(ConfigurationManager.AppSettings["redis_max_write_pool"]);
//private const string ip = "127.0.0.1";
//private const string port = "6379";
//private const string preheat = "100"; // 设置预热连接数
//private const string connectTimeout = "100"; // 设置连接超时时间
//private const string tryit = "1"; // 设置重试次数
//private const string prefix = "CSRedisTest."; // 设置前缀
//private static readonly string _connectString = $"{ip}:{port},preheat={preheat},connectTimeout={connectTimeout},tryit={tryit},prefix={prefix}";
static CSRedisCacheHelper()
{
//var redisHostStr = ConfigurationManager.AppSettings["redis_server_session"];
var redisHostStr = ReadConfig.Instance.get_redis_server_session;
if (!string.IsNullOrEmpty(redisHostStr))
{
//redis = new CSRedisClient(redisHostStr);//+ ",password=,defaultDatabase=0,poolsize=500,ssl=false,writeBuffer=10240,prefix=");
//RedisHelper.Initialization(redis);
//redis = new CSRedisClient[2];
redis = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=1");
//redis[1] = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=1");
}
}
/// <summary>
/// 添加缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void Set<T>(string key, T value)
{
redis.Set(key, value, SessionExpireMinutes * 60);
}
public static T Get<T>(string key)
{
return redis.Get<T>(key);
}
public static void Forever<T>(string key, T value)
{
redis.Set(key, value, -1);
}
public static void Del(string key)
{
redis.Del(key);
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="key"></param>
/// <param name="mac"></param>
/// <returns></returns>
public static bool Contains(string key, string mac)
{
bool result = redis.Exists(mac);
if (!result)
{
result = redis.Exists(key);
}
return result;
}
public static bool Contains(string key)
{
bool result = redis.Exists(key);
return result;
}
/// <summary>
/// 添加Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void HMSet<T>(string key, T value)
{
redis.HMSet(key, value);
}
/// <summary>
/// 获取Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static T[] HMGet<T>(string key)
{
return redis.HMGet<T>(key);
}
/// <summary>
/// 删除Hash缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public static long HDel<T>(string key)
{
return redis.HDel(key);
}
public static void Publish(string Key,string Message)
{
redis.Publish(Key, Message);
}
}
}

22
LogCap/Common/CacheKey.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogCap.Common
{
public class CacheKey
{
public static string RoomIP_Port_Prefix = "Log_IP_Port";
public static string Key = "monitor_host";
public static string MonitorLogPrefix = "AllLogKey";
public static string MonitorEndPointList= "MonitorEndPointList";
}
}

View File

@@ -0,0 +1,547 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Common;
using Commonlib;
using LogCap.Entity;
using MathNet.Numerics.Distributions;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using NLog;
using RCUHost.Implement;
using RCUHost.Protocols;
using RestSharp;
namespace LogCap.Common
{
public class DealWithData
{
private static Logger _logger = LogManager.GetCurrentClassLogger();
public static void HandleData(List<byte> data, string source_ip, ushort source_port, string dest_ip, ushort dest_port)
{
try
{
string fg = Tools.ByteToString(data.ToArray());
Program.CurrentTime = DateTime.Now;
List<byte> Header = data.Take(2).ToList();
List<byte> Len = data.Skip(2).Take(2).ToList();
int Len_int = BitConverter.ToInt16(Len.ToArray(), 0);
//系统 ID 的四个字节。固定“T3SA”
List<byte> ID = data.Skip(4).Take(4).ToList();
//命令字
List<byte> CMD = data.Skip(8).Take(1).ToList();
//Frame
List<byte> Frame = data.Skip(9).Take(2).ToList();
//Project_Code
List<byte> Project_Code = data.Skip(11).Take(2).ToList();
List<byte> IP3 = data.Skip(13).Take(1).ToList();
List<byte> IP4 = data.Skip(14).Take(1).ToList();
List<byte> MsgData = data.Skip(15).Take(Len_int - 15 - 2).ToList();
List<byte> CRC_byte = data.TakeLast(2).ToList();
string Key = string.Format("{0}_{1}_{2}", CacheKey.RoomIP_Port_Prefix, source_ip, source_port);
string Dest_Key = string.Format("{0}_{1}_{2}", CacheKey.RoomIP_Port_Prefix, dest_ip, dest_port);
//Console.WriteLine("Key is: " + Key);
byte cmdType_byte = CMD[0];
BLWCommandType cmdtype = (BLWCommandType)cmdType_byte;
string CommandType = cmdtype.ToString();
string? iii = ReadConfig.Instance.monitor_server_ip;
int ppp = ReadConfig.Instance.monitor_server_port;
var QQQSSS = Program.Cache.Get<List<MonitorEndPoint>>(CacheKey.MonitorEndPointList);
if (QQQSSS.Count > 0)
{
string S_R_Type = "";
if (source_port == ppp && source_ip.Equals(iii))
{
S_R_Type = ConstKey.Send_TX;
}
else
{
S_R_Type = ConstKey.Receive_RX;
}
foreach (var item in QQQSSS)
{
if (item.Port == 0 && item.IPAddress.Equals(source_ip))
{
EndPoint_Monitor(data, source_ip, source_port, CommandType, S_R_Type);
}
else
{
if (item.Port == source_port && item.IPAddress.Equals(source_ip))
{
EndPoint_Monitor(data, source_ip, source_port, CommandType, S_R_Type);
}
}
}
}
//主机注册
if (cmdType_byte == 0x01)
{
//00 00 00 00 服务器 IP 地址
//FF FF FC 00 子网掩码
//C0 A8 64 01 网关
//0D 0D 端口
//34 D0 B8 11 38 89--MAC
List<byte> IP = MsgData.Take(4).ToList();
List<byte> MaskNet = MsgData.Skip(4).Take(4).ToList();
List<byte> GetWay = MsgData.Skip(8).Take(4).ToList();
List<byte> Port = MsgData.Skip(12).Take(2).ToList();
List<byte> MAC_byte = MsgData.Skip(14).Take(6).ToList();
string MACstring = Tools.ByteToString(MAC_byte.ToArray());
MACstring = MACstring.Trim().Replace(" ", "-");
if (Frame.All(A => A == 0xFF))
{
CommandType = "服务器注册命令";
}
if (source_port == ppp && source_ip.Equals(iii))
{
ReallyDealWith(true, data, dest_ip, dest_port, CommandType, ConstKey.Send_TX);
}
else
{
ReallyDealWith(true, data, source_ip, source_port, CommandType);
}
}
//心跳包,其实会维持 连接
else if (cmdType_byte == 0x02)
{
//心跳包
//心跳包 里面有这个 MAC地址
//AA 55 17 00 54 33 53 41
//02
//F9 FF
//A4 06
//2C 69 --这个是IP
//34 D0 B8 11 2C 69
//91 F5
//BLWCommandType cmdtype = (BLWCommandType)cmdType_byte;
//心跳包可能大于17个
//有一些项目的 心跳包是 这样的
// aa 55 17 00 54 33 53 41 02 26 ae e9 03 46 b6 34 d0 b8 11 46 b6 29 7e
if (source_port == ppp && source_ip.Equals(iii))
{
ReallyDealWith(true, data, dest_ip, dest_port, CommandType, ConstKey.Send_TX);
}
else
{
ReallyDealWith(true, data, source_ip, source_port, CommandType);
}
}
else
{
//有时候经常上报这样的数据:
//AA 55 11 00 54 33 53 41 0E FF FF BF 06 0A C8 E7 72
//AA 55 11 00 54 33 53 41 0E FF FF BF 06 0A C6 66 B6
//设备状态上报
if (cmdType_byte == 0x0E)
{
if (MsgData != null && MsgData.Count > 0)
{
//设备的数量
byte[] couont = MsgData.Skip(7).Take(1).ToArray();
int Count = couont[0];
var MMN = MsgData.Skip(8);
for (int j = 0; j < Count; j++)
{
var DeviceData = MMN.Skip(j * 5).Take(5).ToArray();
if (DeviceData[0] == 0x0A)
{
byte n1 = DeviceData[0];
byte n2 = DeviceData[1];
byte[] vvv = new byte[] { DeviceData[4] };
BitArray bitArray = new BitArray(vvv);
//卡身份
var qqq1 = bitArray.Cast<bool>().Take(1).ToArray();
var qqq2 = bitArray.Cast<bool>().Skip(1).Take(3).ToArray();
var qqq3 = qqq2.ToArray().Prepend(false).ToArray();
//节能状态
byte hhhg1 = Tools.CombineBitsToByte(qqq3[3], qqq3[2], qqq3[1], qqq3[0]);
}
}
}
}
if (source_port == ppp && source_ip.Equals(iii))
{
ReallyDealWith(false, data, dest_ip, dest_port, CommandType, ConstKey.Send_TX);
}
else
{
ReallyDealWith(false, data, source_ip, source_port, CommandType);
}
}
}
catch (Exception ex)
{
_logger.Error(ex.Message);
_logger.Error(ex.StackTrace);
Console.WriteLine(ex.Message + " \r\n" + ex.StackTrace);
}
}
/// <summary>
/// IP 和端口 端结点监控
/// </summary>
/// <param name="isRegister"></param>
/// <param name="data"></param>
/// <param name="source_ip"></param>
/// <param name="source_port"></param>
/// <param name="cmdtype"></param>
/// <param name="Send_Or_Receive"></param>
private static void EndPoint_Monitor(List<byte> data, string source_ip, ushort source_port, string cmdtype, string Send_Or_Receive = ConstKey.Receive_RX)
{
try
{
////系统 ID 的四个字节。固定“T3SA”
//List<byte> ID = data.Skip(4).Take(4).ToList();
////命令字
//List<byte> CMD = data.Skip(8).Take(1).ToList();
////Frame
//List<byte> Frame = data.Skip(9).Take(2).ToList();
//Project_Code
List<byte> Project_Code = data.Skip(11).Take(2).ToList();
ushort hotel_code_o = BitConverter.ToUInt16(Project_Code.ToArray(), 0);
////MAC
//List<byte> IP3 = data.Skip(13).Take(1).ToList();
//List<byte> IP4 = data.Skip(14).Take(1).ToList();
long hotel_code = hotel_code_o;
string hostnumber = "";
string hexdata = Tools.ByteToString(data.ToArray());
HttpSend.SendLog_2(cmdtype, hotel_code, 0, "", hostnumber, source_ip, source_port, "", 0, "", Send_Or_Receive, hexdata);
}
catch (Exception)
{
throw;
}
}
private static void ReallyDealWith(bool isRegister, List<byte> data, string source_ip, ushort source_port, string cmdtype, string Send_Or_Receive = ConstKey.Receive_RX)
{
try
{
if (data == null || data.Count == 0)
{
return;
}
ReceiverContext context = new ReceiverContext(data.ToArray());
context.SystemHeader = DecodeSystemHeader(context.Data);
string Ghostnumber = context.SystemHeader.Value.HostNumber.ToString() ?? "";
if (string.IsNullOrEmpty(Ghostnumber))
{
return;
}
var list = Program.Cache.Get<List<Monitor_Host>>(CacheKey.Key);
if (list == null)
{
return;
}
if (list.Count == 0)
{
return;
}
if (isRegister)
{
if (list != null && list.Count > 0)
{
#region
try
{
list.RemoveAll((Item) =>
{
if (Item != null)
{
var ddt = Item.CreateDateTime;
if (!string.IsNullOrEmpty(ddt))
{
DateTime dta = DateTime.Parse(ddt);
DateTime nnn = dta.AddDays(30);
if (DateTime.Now >= nnn)
{
return true;
}
}
}
return false;
});
}
catch (Exception)
{
}
#endregion
foreach (Monitor_Host item in list)
{
try
{
if (item == null)
{
continue;
}
string HostNNN = item.Key_HostNumber;
if (HostNNN == null)
{
continue;
}
string room_num = item.RoomNumber;
string TakeOut_MAC = item.MAC;
string hotelcode = item.HotelCode;
//如果 要监控的MAC 和 当前上传的MAC相等
if (HostNNN.Equals(Ghostnumber))
{
//心跳包可以注册
if (isRegister)
{
var llg = Tools.ByteToString(data.ToArray());
string KeyHeartBeat = string.Format("{0}_{1}_{2}", CacheKey.RoomIP_Port_Prefix, source_ip, source_port);
//Console.WriteLine("TakeOut_HostNUMBER: " + HostNNN + " Key: " + KeyHeartBeat + " MAC: " + TakeOut_MAC + " data:" + llg);
Program.Cache.Set<string>(KeyHeartBeat, HostNNN);
}
string Key = string.Format("{0}_{1}", CacheKey.RoomIP_Port_Prefix, HostNNN);
var takeMM = Program.Cache.Get<MonitorRedis>(Key);
//如果房间为空
if (takeMM == null)
{
#region
//从数据库里面查询得
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("key", "blw_ws@2015");
dic.Add("roomnumber", room_num);
dic.Add("hotelcode", hotelcode);
string sttr = "";
string KKK = "ChaXunData_" + hotelcode + "_" + room_num;
string GGG = Program.Cache.Get<string>(KKK);
if (!string.IsNullOrEmpty(GGG))
{
sttr = GGG;
}
else
{
sttr = Send_Http_Request_Params("api/GetHostByMAC_POST", dic);
Program.Cache.Set<string>(KKK, GGG, new MemoryCacheEntryOptions()
{
SlidingExpiration = TimeSpan.FromMinutes(10)
});
}
if (!string.IsNullOrEmpty(sttr))
{
//Console.WriteLine( "查询的数据:"+sttr);
var msghost = JsonConvert.DeserializeObject<HostMsg>(sttr);
var dtrow = msghost.Result.FirstOrDefault();
if (dtrow != null)
{
string? hotelid = dtrow["HotelID"].ToString();
string? hostid = dtrow["ID"].ToString();
string? roomno = dtrow["RoomNumber"].ToString();
string? hostnumber = dtrow["HostNumber"].ToString();
string? LanIP = dtrow["LanIP"] ?? "";
string? LanPort = dtrow["LanPort"].ToString();
string? HotelID = dtrow["HotelID"].ToString();
//string? XiaoDuCUID = dtrow["XiaoDuCUID"].ToString();
//string? TiaoMaoCUID = dtrow["TiaoMaoCUID"].ToString();
string? XiaoDuCUID = "";
string? TiaoMaoCUID = "";
MonitorRedis mm = new MonitorRedis();
long hhh = 0;
long.TryParse(hotelcode, out hhh);
int hid = 0;
int.TryParse(HotelID, out hid);
mm.TiaoMaoCUID = TiaoMaoCUID;
mm.XiaoDuCUID = XiaoDuCUID;
mm.HotelCode = hhh;
mm.HotelID = hid;
mm.HostID = int.Parse(hostid);
mm.RoomNo = roomno;
mm.HostNumber = hostnumber;
mm.WWW_IP = source_ip;
mm.WWW_Port = source_port;
mm.LanIP = LanIP;
mm.LanPort = int.Parse(LanPort);
mm.MAC = TakeOut_MAC;
mm.CommandType = cmdtype.ToString();
mm.SendOrReceive = Send_Or_Receive;
mm.RemoteEndPointIP = source_ip;
mm.RemoteEndPointPort = source_port;
Program.Cache.Set<MonitorRedis>(Key, mm);
string dataHex = Tools.ByteToString(data.ToArray());
HttpSend.SendLog(mm.XiaoDuCUID, mm.TiaoMaoCUID, mm.CommandType, hhh, mm.HostID, mm.RoomNo, mm.HostNumber, source_ip, source_port, mm.LanIP, mm.LanPort, mm.MAC, Send_Or_Receive, dataHex);
}
}
#endregion
}
else
{
long hotel_code = takeMM.HotelCode;
int host_id = takeMM.HostID;
string hostnumber = takeMM.HostNumber;
string roomnumber = takeMM.RoomNo;
string lan_ip = takeMM.LanIP;
int lan_port = takeMM.LanPort;
string www_ip = takeMM.WWW_IP;
int www_port = takeMM.WWW_Port;
string mac_take_out = takeMM.MAC;
string dataHex = Tools.ByteToString(data.ToArray());
HttpSend.SendLog(takeMM.XiaoDuCUID, takeMM.TiaoMaoCUID, cmdtype, hotel_code, host_id, roomnumber, hostnumber, www_ip, www_port, lan_ip, lan_port, mac_take_out, Send_Or_Receive, dataHex);
}
break;
}
}
catch (Exception ex)
{
continue;
}
}
}
}
else
{
if (list != null && list.Count > 0)
{
string KeyHeartBeat = string.Format("{0}_{1}_{2}", CacheKey.RoomIP_Port_Prefix, source_ip, source_port);
string Hostnumber_TTT = Program.Cache.Get<string>(KeyHeartBeat);
if (!string.IsNullOrEmpty(Hostnumber_TTT))
{
string Key = string.Format("{0}_{1}", CacheKey.RoomIP_Port_Prefix, Hostnumber_TTT);
//Console.WriteLine("KeyHeartBeat is " + KeyHeartBeat);
if (!string.IsNullOrEmpty(Key))
{
//string bbbaaa=Tools.ByteToString(data.ToArray());
//Console.WriteLine("111111111111111111: "+Key+" data: "+bbbaaa);
var takeMM = Program.Cache.Get<MonitorRedis>(Key);
if (takeMM != null)
{
//Console.WriteLine("22222222222");
long hotel_code = takeMM.HotelCode;
int host_id = takeMM.HostID;
string hostnumber = takeMM.HostNumber;
string roomnumber = takeMM.RoomNo;
string lan_ip = takeMM.LanIP;
int lan_port = takeMM.LanPort;
string www_ip = takeMM.WWW_IP;
int www_port = takeMM.WWW_Port;
string mac_take_out = takeMM.MAC;
string dataHex = Tools.ByteToString(data.ToArray());
HttpSend.SendLog("", "", cmdtype, hotel_code, host_id, roomnumber, hostnumber, www_ip, www_port, lan_ip, lan_port, mac_take_out, Send_Or_Receive, dataHex);
}
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("出错了" + ex.Message);
Console.WriteLine("出错了" + ex.StackTrace);
_logger.Error(ex.Message);
_logger.Error(ex.StackTrace);
}
}
private static SystemHeader? DecodeSystemHeader(byte[] data)
{
return StructConverter.BytesToStruct(data, typeof(SystemHeader)) as SystemHeader?;
}
public static string Send_Http_Request_Params(string Url, Dictionary<string, string> Params)
{
string BaseUrl = ReadConfig.Instance.CRICS_URL;
var options = new RestClientOptions(BaseUrl);
var client = new RestClient(options);
var request = new RestRequest(Url);
foreach (var item in Params)
{
request.AddParameter(item.Key, item.Value);
}
//RoomNumber
// The cancellation token comes from the caller. You can still make a call without it.
string? hostlist = client.Post(request).Content;
return hostlist;
}
}
}

108
LogCap/Common/HttpSend.cs Normal file
View File

@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LogCap.Entity;
using Microsoft.VisualBasic;
using MQTTnet;
using RestSharp;
namespace LogCap.Common
{
public class HttpSend
{
public static readonly string debug_log_report_url = ReadConfig.Instance.get_debug_log_report_url;
public static readonly string debug_log_report_mqtt_topic = ReadConfig.Instance.get_debug_log_report_mqtt_topic;
public static readonly string debug_log_report_mqtt_topic_new = "blw/rcu/monitor/endpoint";
//public static RestClient client1 = new RestClient(debug_log_report_url);
public static async void SendLog(string xiaodu, string tianmao, string MyCommandType, long hotel_code, int host_id, string roomnumber, string hostnumber, string WWW_IP, int WWW_Port, string lan_ip, int lan_port, string mac, string send_or_receive, string dataHex)
{
try
{
//if (hostnumber.Equals("061004043027"))
//{
// Console.WriteLine("研发发布mqtt");
//}
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MonitorLog mm = new MonitorLog();
mm.HotelCode = hotel_code;
mm.HostID = host_id;
mm.HostNumber = hostnumber;
mm.RoomNo = roomnumber;
mm.LanIP = lan_ip;
mm.LanPort = lan_port;
mm.WWW_IP = WWW_IP;
mm.WWW_Port = WWW_Port;
mm.MAC = mac;
mm.SendOrReceive = send_or_receive;
mm.CommandType = MyCommandType;
mm.Data = dataHex;
mm.CreateTime = ti;
mm.XiaoDuCUID = xiaodu;
mm.TiaoMaoCUID = tianmao;
string str = Newtonsoft.Json.JsonConvert.SerializeObject(mm);
//Console.WriteLine("发送MQTT的数据为" + str);
//var request1 = new RestRequest("/", Method.Post);
////注意方法是POST
////两个参数名字必须是 topic 和payload ,区分大小写的
////Console.WriteLine("Topic: " + debug_log_report_mqtt_topic);
//request1.AddParameter("topic", debug_log_report_mqtt_topic);
//request1.AddParameter("payload", str);
//await HttpSend.client1.ExecuteAsync(request1);
//Console.WriteLine("当前时间为:" + ti+" Data: "+dataHex);
//var payload_data= Encoding.UTF8.GetBytes(str);
await Program.mqttClient.PublishStringAsync(debug_log_report_mqtt_topic, str);
}
catch (Exception ex)
{
Console.WriteLine("发送MQTT数据出错" + ex.Message);
}
}
public static async void SendLog_2(string MyCommandType, long hotel_code, int host_id, string roomnumber, string hostnumber, string WWW_IP, int WWW_Port, string lan_ip, int lan_port, string mac, string send_or_receive, string dataHex)
{
try
{
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MonitorLog mm = new MonitorLog();
mm.HotelCode = hotel_code;
mm.HostID = host_id;
mm.HostNumber = hostnumber;
mm.RoomNo = roomnumber;
mm.LanIP = lan_ip;
mm.LanPort = lan_port;
mm.WWW_IP = WWW_IP;
mm.WWW_Port = WWW_Port;
mm.MAC = mac;
mm.SendOrReceive = send_or_receive;
mm.CommandType = MyCommandType;
mm.Data = dataHex;
mm.CreateTime = ti;
mm.XiaoDuCUID = "";
mm.TiaoMaoCUID = "";
string str = Newtonsoft.Json.JsonConvert.SerializeObject(mm);
await Program.mqttClient.PublishStringAsync(debug_log_report_mqtt_topic_new, str);
}
catch (Exception ex)
{
Console.WriteLine("发送MQTT数据出错" + ex.Message);
}
}
}
}

110
LogCap/Common/LogExecute.cs Normal file
View File

@@ -0,0 +1,110 @@
using System.Configuration;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using PacketDotNet;
using SharpPcap;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace LogCap.Common
{
public class LogExecute
{
public static string FilterStr = ReadConfig.Instance.get_monitor_filter;
public Task Execute(int i)
{
Console.WriteLine("过滤的: " + FilterStr);
var device2 = CaptureDeviceList.Instance[i];
PubRepository.liveDevice = device2;
int readTimeoutMilliseconds = 2000;
// Register our handler function to the 'packet arrival' event
device2.OnPacketArrival +=
new PacketArrivalEventHandler(device_OnPacketArrival);
// Open the devices for capturing
device2.Open(DeviceModes.Promiscuous, readTimeoutMilliseconds);
// set the filters
device2.Filter = FilterStr;
Console.WriteLine("device2.Filter {0} ", device2.Filter);
Console.WriteLine();
Console.WriteLine("-- Listening on {0} {1}, hit 'Enter' to stop...",
device2.Name, device2.Description);
// Start the capturing process
//device1.StartCapture();
device2.StartCapture();
return Task.CompletedTask;
}
public static long TotalCountGlobal = 0;
private static void device_OnPacketArrival(object sender, PacketCapture e)
{
try
{
var rawPacket = e.GetPacket();
var time = rawPacket.Timeval.Date;
var len = rawPacket.Data.Length;
var udd = rawPacket.Data;
//Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
// time.Hour, time.Minute, time.Second, time.Millisecond, len);
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
//var ethernetPacket = (EthernetPacket)p;
//// 获取源MAC和目标MAC地址
//string sourceMac = ethernetPacket.SourceHardwareAddress.ToString();
//[IPv4Packet: SourceAddress= 172.16.4.152,
//DestinationAddress = 172.16.4.152,
//HeaderLength = 5, Protocol = Udp, TimeToLive = 128][UDPPacket: SourcePort= 55966, DestinationPort = 1314]
var q = p.PayloadData;
var pff = p.PayloadPacket;
IPAddress SourceAddress = ((PacketDotNet.IPv4Packet)pff).SourceAddress;
ushort SourcePort = ((PacketDotNet.UdpPacket)((PacketDotNet.IPPacket)pff).PayloadPacket).SourcePort;
var DestinationAddress = ((PacketDotNet.IPv4Packet)pff).DestinationAddress;
ushort DestinationPort = ((PacketDotNet.UdpPacket)((PacketDotNet.IPPacket)pff).PayloadPacket).DestinationPort;
int pport = ReadConfig.Instance.monitor_server_port;
string iip = ReadConfig.Instance.monitor_server_ip;
if (SourcePort != pport && !iip.Equals(SourceAddress.ToString()))
{
Interlocked.Increment(ref TotalCountGlobal);
}
//上行和下行如何区分
//如果目标IP和端口是 3339和服务器IP的话 就是上行,其它都是下行
byte[] Data = ((PacketDotNet.IPPacket)pff).PayloadPacket.PayloadData;
//ReceiverContext context = new ReceiverContext(Data);
//context.SystemHeader = DecodeSystemHeader(context.Data);
//string hostnumber= context.SystemHeader.Value.HostNumber.ToString();
//028006045045
//253007014192
if (Data.Length > 0)
{
//Console.WriteLine(p.ToString());
Tuple<byte[], IPAddress, ushort, IPAddress, ushort> ddd = new Tuple<byte[], IPAddress, ushort, IPAddress, ushort>(Data, SourceAddress, SourcePort, DestinationAddress, DestinationPort);
Task.Factory.StartNew((State) =>
{
var tf = State as Tuple<byte[], IPAddress, ushort, IPAddress, ushort>;
DealWithData.HandleData(tf.Item1.ToList(), tf.Item2.ToString(), tf.Item3, tf.Item4.ToString(), tf.Item5);
}, ddd);
}
}
catch (Exception ex)
{
}
}
}
}

View File

@@ -0,0 +1,73 @@
using SharpPcap;
namespace LogCap.Common
{
public class PubRepository
{
public static LogExecute log { get; set; }
public static ILiveDevice liveDevice { get; set; }
public static List<DDD> GetDeviceList()
{
var ver = Pcap.SharpPcapVersion;
if (CaptureDeviceList.Instance.Count < 1)
{
Console.WriteLine("No devices were found on this machine");
}
int i = 0;
List<DDD> list = new List<DDD>();
foreach (ILiveDevice dev in CaptureDeviceList.Instance)
{
DDD dd = new DDD();
dd.Name = dev.Name;
dd.Description = dev.Description;
list.Add(dd);
Console.WriteLine("{2} <> {0} {1}", dev.Name, dev.Description, i);
i++;
}
return list;
}
public bool GetMonitor_Status()
{
return PubRepository.liveDevice.Started;
}
public static void StartMonitor(int i)
{
PubRepository.log = new LogExecute();
PubRepository.log.Execute(i);
}
public static void StopMonitor()
{
try
{
PubRepository.liveDevice.StopCapture();
PubRepository.liveDevice.Dispose();
PubRepository.log = null;
}
catch (Exception)
{
}
}
public string Test()
{
return "hello";
}
}
public class DDD
{
public string Name { get; set; }
public string Description { get; set; }
}
}

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace LogCap.Common
{
public class ReadConfig
{
public static ReadConfig Instance = new ReadConfig();
public IConfiguration? Configuration { get; set; }
public string? MySQLConnectionString { get; set; }
public string? get_monitor_filter { get; set; }
public string? get_session_expire_minutes { get; set; }
public string? get_redis_server_session { get; set; }
public string? get_redis_max_read_pool { get; set; }
public string? get_redis_max_write_pool { get; set; }
public string? get_debug_log_report_url { get; set; }
public string? get_debug_log_report_mqtt_topic { get; set; }
public string? monitor_log_expire_minutes { get; set; }
public string? monitor_server_ip { get; set; }
public int monitor_server_port { get; set; }
public string? CRICS_URL { get; set; }
public string? MQTT_ServerIP { get; set; }
public int? MQTT_ServerPort { get; set; }
public string? MQTT_User { get; set; }
public string? MQTT_PassWord { get; set; }
public ReadConfig()
{
Configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("app.json").Build();
MySQLConnectionString = Configuration.GetConnectionString("SQLServerConnectionString");
get_monitor_filter = Configuration.GetSection("monitor_filter").Value;
get_session_expire_minutes = Configuration.GetSection("session_expire_minutes").Value;
get_redis_server_session = Configuration.GetSection("redis_server_session").Value;
get_redis_max_read_pool = Configuration.GetSection("redis_max_read_pool").Value;
get_redis_max_write_pool = Configuration.GetSection("redis_max_write_pool").Value;
monitor_log_expire_minutes = Configuration.GetSection("monitor_log_expire_minutes").Value;
get_debug_log_report_url = Configuration.GetSection("debug_log_report_url").Value;
get_debug_log_report_mqtt_topic = Configuration.GetSection("debug_log_report_mqtt_topic").Value;
monitor_server_ip = Configuration.GetSection("monitor_server_ip").Value;
int i = 3339;
int.TryParse(Configuration.GetSection("monitor_server_port").Value, out i);
monitor_server_port = i;
MQTT_ServerIP = Configuration.GetSection("MQTT_ServerIP").Value;
int p = 1883;
int.TryParse(Configuration.GetSection("MQTT_ServerPort").Value, out p);
MQTT_ServerPort = p;
CRICS_URL = Configuration.GetSection("CRICS_URL").Value;
MQTT_User = Configuration.GetSection("MQTT_User").Value;
MQTT_PassWord = Configuration.GetSection("MQTT_PWD").Value;
}
}
}

12
LogCap/Common/TCache.cs Normal file
View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogCap.Common
{
internal class TCache
{
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogCap.Entity
{
public class MonitorLog
{
public long HotelCode { get; set; }
public int HotelID { get; set; }
public int HostID { get; set; }
public string HostNumber { get; set; }
public string RoomNo { get; set; }
public string LanIP { get; set; }
public int LanPort { get; set; }
public string WWW_IP { get; set; }
public int WWW_Port { get; set; }
public string MAC { get; set; }
public string CommandType { get; set; }
public string SendOrReceive { get; set; }
public string Data { get; set; }
public string? CreateTime { get; set; }
public string? XiaoDuCUID { get; set; }
public string? TiaoMaoCUID { get; set; }
}
public class MonitorRedis : MonitorLog
{
public string RemoteEndPointIP { get; set; }
public int RemoteEndPointPort { get; set; }
}
}

46
LogCap/LogCap.csproj Normal file
View File

@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Content Include="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.8.803" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="9.0.0" />
<PackageReference Include="MQTTnet" Version="5.0.1.1416" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="4.3.7.1207" />
<PackageReference Include="NetMQ" Version="4.0.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="NLog.Schema" Version="5.3.4" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="SharpPcap" Version="6.3.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Commonlib\Commonlib.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="app.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>E:\tian\BLWLogMonitor\LogCap\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>

254
LogCap/Program.cs Normal file
View File

@@ -0,0 +1,254 @@
using Common;
using Commonlib;
using LogCap.Common;
using LogCap.Entity;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.VisualBasic;
using MQTTnet;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using NetMQ;
using NetMQ.Sockets;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using RestSharp.Authenticators.OAuth2;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace LogCap
{
public class Program
{
public static MemoryCache Cache = new MemoryCache(new MemoryCacheOptions { });
public static IMqttClient mqttClient { get; set; }
public static DateTime CurrentTime { get; set; }
public static int CurrentWangKaBianHao = 0;
public static void Main(string[] args)
{
var NQQ = DateTime.Now.ToString("mmss");
//var server = new ResponseSocket("@tcp://127.0.0.1:5556");
//while (true)
//{
// string frame = server.ReceiveFrameString();
// Console.WriteLine("Server received frame={0}", frame);
//}
//Console.ReadLine();
//string SSS = Guid.NewGuid().ToString("N");
//CurrentTime = DateTime.Now;
// var authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(
//"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2NGZjYjhjMS1jZDZjLTRkMTktOTc3My05YzkxYmZhNjQ2YWQiLCJpYXQiOjE3NDEyNDczNDAsImV4cCI6MTc0MTI1ODE0MCwic2NoZW1hIjoibnhnXzcwNzA1OTEzX2VhcXoiLCJ1c2VyIjoiYWYwNzg3YTQtMmM2NC00NWRiLWEzMjktNzg0ZGYwZWRjOGZjIiwiZGVmYXVsdF9wcm9wZXJ0eSI6IjA3MTY3M2IzLWQ4OTMtNDQwYi1iM2YwLTY0YTBkOTY0ZWIyOSIsInRvX3JlZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MiLCJpbml0X2Vwb2NoIjoxNzQxMjQ3MzQwLCJtZWRpdW1fY29kZSI6IldFQiJ9.4k2GE08J3MZQIgRKOx5dYmeL1vSnqDSC11MLpkDNjqQ", "token");
// var options = new RestClientOptions("https://api.fcs1cloud.com")
// {
// //Authenticator = authenticator
// };
// var client = new RestClient(options);
// //string str = Newtonsoft.Json.JsonConvert.SerializeObject(mm);
// //Console.WriteLine("发送MQTT的数据为" + str);
// var request1 = new RestRequest("/api-secure/job/request", Method.Post);
// request1.AddHeader("token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2NGZjYjhjMS1jZDZjLTRkMTktOTc3My05YzkxYmZhNjQ2YWQiLCJpYXQiOjE3NDEyNDczNDAsImV4cCI6MTc0MTI1ODE0MCwic2NoZW1hIjoibnhnXzcwNzA1OTEzX2VhcXoiLCJ1c2VyIjoiYWYwNzg3YTQtMmM2NC00NWRiLWEzMjktNzg0ZGYwZWRjOGZjIiwiZGVmYXVsdF9wcm9wZXJ0eSI6IjA3MTY3M2IzLWQ4OTMtNDQwYi1iM2YwLTY0YTBkOTY0ZWIyOSIsInRvX3JlZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MiLCJpbml0X2Vwb2NoIjoxNzQxMjQ3MzQwLCJtZWRpdW1fY29kZSI6IldFQiJ9.4k2GE08J3MZQIgRKOx5dYmeL1vSnqDSC11MLpkDNjqQ");
// //注意方法是POST
// //两个参数名字必须是 topic 和payload ,区分大小写的
// //Console.WriteLine("Topic: " + debug_log_report_mqtt_topic);
var list = CSRedisCacheHelper.Get<List<Monitor_Host>>(CacheKey.Key);
Cache.Set<List<Monitor_Host>>(CacheKey.Key, list);
//端点监控
var QQQ = CSRedisCacheHelper.Get<List<MonitorEndPoint>>(CacheKey.MonitorEndPointList);
Cache.Set<List<MonitorEndPoint>>(CacheKey.MonitorEndPointList, QQQ);
_ = Start_MqttClient();
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += Timer_Elapsed;
timer.Interval = 10000;
timer.Enabled = true;
timer.Start();
System.Timers.Timer timer1 = new System.Timers.Timer();
timer1.Elapsed += Timer1_Elapsed;
timer1.Interval = 60000;
timer1.Enabled = true;
timer1.Start();
PubRepository.GetDeviceList();
Console.WriteLine("选择你要监控的网卡");
//string whitchone = Console.ReadLine();
string whitchone = "3";
int.TryParse(whitchone, out CurrentWangKaBianHao);
PubRepository.StartMonitor(CurrentWangKaBianHao);
Console.WriteLine("正在监控中");
Console.WriteLine("……………………………………………………………………………………………………………………………………………………………………………………");
Console.WriteLine("按回车键就结束");
string? nnn = Console.ReadLine();
PubRepository.StopMonitor();
timer.Dispose();
}
private static async void Timer1_Elapsed(object? sender, ElapsedEventArgs e)
{
try
{
Console.WriteLine("现在的数量是:"+LogExecute.TotalCountGlobal);
long lla= Interlocked.Read(ref LogExecute.TotalCountGlobal);
CSRedisCacheHelper.Publish("wireshark-cap-udp-totalcount",lla.ToString());
Interlocked.Exchange(ref LogExecute.TotalCountGlobal, 0);
}
catch (Exception)
{
}
}
private static async Task MqttClient_DisconnectedAsync(MqttClientDisconnectedEventArgs arg)
{
Console.WriteLine("断线重连了");
await Task.Delay(3000);
await Start_MqttClient();
}
private static Task MqttClient_ApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs arg)
{
try
{
var str = arg.ApplicationMessage.Payload;
string nnn = Encoding.UTF8.GetString(str);
Monitor_Host? vvv = JsonConvert.DeserializeObject<Monitor_Host>(nnn);
if (vvv != null)
{
string Key = string.Format("{0}_{1}", CacheKey.RoomIP_Port_Prefix, vvv.Key_HostNumber);
var takeMM = Program.Cache.Get<MonitorRedis>(Key);
if (takeMM != null)
{
string IP = takeMM.WWW_IP;
int Port = takeMM.WWW_Port;
string KeyHeartBeat = string.Format("{0}_{1}_{2}", CacheKey.RoomIP_Port_Prefix, IP, Port);
Program.Cache.Remove(KeyHeartBeat);
}
}
}
catch (Exception ex)
{
Console.WriteLine("MqttClient_ApplicationMessageReceivedAsync: " + ex.Message);
}
return Task.CompletedTask;
}
private static async void Timer_Elapsed(object? sender, ElapsedEventArgs e)
{
try
{
Console.WriteLine("定时任务");
var list = CSRedisCacheHelper.Get<List<Monitor_Host>>(CacheKey.Key);
Cache.Set<List<Monitor_Host>>(CacheKey.Key, list);
if (list != null && list.Count != 0)
{
TimeSpan span = DateTime.Now - Program.CurrentTime;
if (span.TotalSeconds >= 35)
{
PubRepository.StopMonitor();
PubRepository.StartMonitor(CurrentWangKaBianHao);
}
}
//端点监控
var QQQ = CSRedisCacheHelper.Get<List<MonitorEndPoint>>(CacheKey.MonitorEndPointList);
Cache.Set<List<MonitorEndPoint>>(CacheKey.MonitorEndPointList, QQQ);
var hhh = await mqttClient.PublishStringAsync("/blw/heart/logcap", "heartbeat");
if (hhh.IsSuccess == false)
{
await Start_MqttClient();
}
}
catch (Exception ex)
{
Console.WriteLine("timer_elapsed: " + ex.Message);
}
}
async public static Task Start_MqttClient()
{
try
{
var mqttFactory = new MqttClientFactory();
string? ip = ReadConfig.Instance.MQTT_ServerIP;
int? port = ReadConfig.Instance.MQTT_ServerPort;
string? username = ReadConfig.Instance.MQTT_User;
string? pwd = ReadConfig.Instance.MQTT_PassWord;
//long lid = Tools.ToUnixTimestampBySeconds(DateTime.Now);
string lid = Guid.NewGuid().ToString("N");
string ID = $"logmonitor_{lid}";
mqttClient = mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId(ID)
.WithTcpServer(ip, port)
.WithCredentials(username, pwd)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.Build();
mqttClient.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceivedAsync;
mqttClient.DisconnectedAsync += MqttClient_DisconnectedAsync;
await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
//var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
// .WithTopicFilter("blw/logmonitor/delete/report")
// .Build();
//var nnn = new MqttTopicFilterBuilder().WithTopic("blw/logmonitor/delete/report");
var subscribeOptions = new MqttClientSubscribeOptions();
var topicFilter = new MqttTopicFilter
{
Topic = "blw/logmonitor/delete/report"
};
subscribeOptions.TopicFilters.Add(topicFilter);
await mqttClient.SubscribeAsync(subscribeOptions, CancellationToken.None);
}
catch (Exception ex)
{
Console.WriteLine("Start_MqttClient: " + ex.Message);
}
}
}
public class GGH
{
public List<string> location_uuid { get; set; }
public List<GGJ> service_items { get; set; }
public string remark { get; set; }
public string assigned_to { get; set; }
public int user_type { get; set; }
}
public class GGJ
{
public string item_uuid { get; set; }
public int quantity { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2025-11-18T02:38:51.0970145Z||;True|2025-11-18T10:38:36.6590100+08:00||;True|2025-11-18T09:55:20.7541888+08:00||;True|2025-11-18T09:54:09.8014429+08:00||;True|2025-11-18T09:03:03.6239935+08:00||;True|2025-11-12T13:37:44.5193799+08:00||;True|2025-11-04T19:04:11.1977717+08:00||;True|2025-10-15T14:12:11.7503437+08:00||;True|2025-09-29T09:53:03.7995047+08:00||;True|2025-09-29T09:52:00.2305647+08:00||;True|2025-09-29T09:49:50.6101495+08:00||;True|2025-09-29T09:35:55.7152890+08:00||;True|2025-09-29T09:34:28.6196941+08:00||;True|2025-09-29T09:31:27.1029278+08:00||;True|2025-09-29T09:31:20.5804056+08:00||;True|2025-09-29T09:29:27.0993157+08:00||;True|2025-09-29T09:26:09.9458028+08:00||;True|2025-09-11T14:19:22.7215134+08:00||;True|2025-07-21T09:19:25.8321680+08:00||;True|2025-07-18T16:09:34.8867018+08:00||;True|2025-07-18T16:06:18.6358237+08:00||;True|2025-07-18T15:49:28.4034135+08:00||;True|2025-07-18T15:38:30.1452114+08:00||;True|2025-07-18T15:37:55.7831800+08:00||;True|2025-07-18T15:26:49.0230860+08:00||;True|2025-07-18T15:14:11.3917759+08:00||;True|2025-07-18T14:53:35.1351174+08:00||;True|2025-07-18T14:51:40.7222368+08:00||;True|2025-07-18T14:50:19.5264194+08:00||;True|2025-07-18T14:48:37.5000171+08:00||;True|2025-07-18T14:46:06.6645443+08:00||;True|2025-07-18T14:43:35.5161662+08:00||;True|2025-07-18T14:41:32.1953723+08:00||;True|2025-07-18T14:39:41.8990197+08:00||;True|2025-07-18T14:37:59.5226728+08:00||;False|2025-07-18T14:36:34.9869313+08:00||;False|2025-07-18T14:36:28.5844407+08:00||;True|2025-07-18T14:33:19.7559086+08:00||;True|2025-07-18T14:31:58.6399805+08:00||;True|2025-07-18T14:29:41.3500470+08:00||;True|2025-07-18T14:25:09.8903114+08:00||;True|2025-07-18T14:04:10.8844905+08:00||;True|2025-07-18T13:30:11.7855851+08:00||;True|2025-07-18T13:17:27.5926995+08:00||;True|2025-07-16T09:38:37.9415699+08:00||;True|2025-07-16T09:29:01.5138136+08:00||;True|2025-07-16T09:21:08.0981473+08:00||;True|2025-07-15T17:38:31.1667932+08:00||;True|2025-07-15T16:43:05.4527411+08:00||;True|2025-07-07T10:16:09.3877487+08:00||;True|2025-07-07T10:10:49.7560402+08:00||;True|2025-06-17T14:46:41.6347900+08:00||;True|2025-06-17T14:39:33.5356221+08:00||;True|2025-06-17T14:35:00.6059962+08:00||;True|2025-06-16T14:29:42.1186724+08:00||;True|2025-04-10T16:27:27.4571680+08:00||;True|2025-04-10T16:26:52.4704500+08:00||;True|2025-04-10T16:23:44.7512424+08:00||;True|2025-04-10T16:20:38.5807986+08:00||;True|2025-04-10T16:18:39.7753691+08:00||;True|2025-04-10T16:14:06.5114394+08:00||;True|2025-04-09T15:37:02.3941152+08:00||;True|2025-04-09T14:51:04.4433953+08:00||;True|2025-04-09T09:50:05.6074325+08:00||;True|2025-04-08T19:25:32.8536115+08:00||;False|2025-04-08T19:23:51.5364323+08:00||;True|2025-04-08T09:23:44.2543020+08:00||;True|2025-04-08T09:22:54.9082916+08:00||;True|2025-03-31T16:13:42.0797431+08:00||;True|2025-03-31T16:13:15.4339600+08:00||;True|2025-03-31T16:12:35.5470378+08:00||;True|2025-03-31T16:12:06.9833114+08:00||;True|2025-03-31T16:04:47.2437329+08:00||;True|2025-03-31T15:27:09.4504997+08:00||;True|2025-03-14T19:40:25.2983776+08:00||;True|2025-03-10T09:17:51.3361540+08:00||;True|2025-03-10T09:09:10.4750125+08:00||;True|2025-03-08T16:44:19.0185608+08:00||;True|2025-03-08T16:38:26.8544178+08:00||;True|2025-03-07T08:58:41.8621312+08:00||;True|2025-03-07T08:58:23.6999802+08:00||;True|2025-03-05T16:32:51.3089913+08:00||;True|2025-03-05T15:52:19.9963516+08:00||;True|2025-03-05T15:52:02.6859260+08:00||;True|2025-03-04T14:09:36.4338421+08:00||;True|2025-03-04T10:05:44.6777562+08:00||;True|2025-03-04T09:12:49.9348187+08:00||;True|2025-03-03T08:47:09.8416556+08:00||;True|2025-03-03T08:44:56.7823894+08:00||;True|2025-02-21T14:47:27.2104567+08:00||;True|2025-02-21T14:42:30.8494218+08:00||;True|2025-02-21T14:36:24.1989089+08:00||;True|2025-02-21T14:34:10.8466400+08:00||;True|2025-02-21T14:28:18.6904848+08:00||;True|2025-02-21T14:18:04.2323793+08:00||;True|2025-02-21T14:13:25.3047586+08:00||;True|2025-02-21T14:07:51.0808912+08:00||;True|2025-02-21T11:52:04.2644013+08:00||;True|2025-02-18T08:38:44.8636891+08:00||;True|2025-02-17T15:03:01.3963923+08:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

29
LogCap/app.json Normal file
View File

@@ -0,0 +1,29 @@
{
"ConnectionStrings": {
"SQLServerConnectionString": "server=WIN-061EVIHKD86\\BLW;database=CRICS;uid=sa;pwd=pass@123$%^;"
//"MysqlConnStr": "Data Source=DESKTOP-DUNS5K7;Initial Catalog=CRICS;User ID=sa;Password=123456;Trust Server Certificate=True"
},
//服务器的IP
"monitor_server_ip": "127.0.0.1",
"monitor_server_port": 3339,
"monitor_filter": "udp port 3339",
//redis
"session_expire_minutes": "5",
"redis_server_session": "127.0.0.1:6379",
"redis_max_read_pool": "1000",
"redis_max_write_pool": "1000",
"monitor_log_expire_minutes": 30,
"debug_log_report_url": "http://localhost:8086/blw/mqtt_publish",
"debug_log_report_mqtt_topic": "blw/log/report",
"CRICS_URL": "https://www.boonlive-rcu.com",
"MQTT_ServerIP": "120.24.73.62",
"MQTT_ServerPort": 1883,
"MQTT_User": "blw",
"MQTT_PWD": "blw@1234"
}

35
LogCap/nlog.config Normal file
View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- enable asp.net core layout renderers -->
<targets>
<!--项目日志保存文件路径说明fileName="${basedir}/保存目录,以年月日的格式创建/${shortdate}/${记录器名称}-${单级记录}-${shortdate}.txt"-->
<target name="info_file" xsi:type="File"
fileName="${basedir}/Logs/${shortdate}/info_${shortdate}.txt"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString} ${newline} ${stacktrace} ${newline}"
archiveFileName="${basedir}/archives/info_${shortdate}-{#####}.txt"
archiveAboveSize="102400"
archiveNumbering="Sequence"
concurrentWrites="true"
keepFileOpen="false" />
<target name="error_file" xsi:type="File"
fileName="${basedir}/Logs/${shortdate}/error_${shortdate}.txt"
layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString} ${newline} ${stacktrace} ${newline}"
archiveFileName="${basedir}/archives/error_${shortdate}-{#####}.txt"
archiveAboveSize="102400"
archiveNumbering="Sequence"
concurrentWrites="true"
keepFileOpen="false" />
</targets>
<!--规则配置,final - 最终规则匹配后不处理任何规则-->
<!--规则配置,final - 最终规则匹配后不处理任何规则-->
<!--定义使用哪个target输出-->
<rules>
<!-- 优先级从高到低依次为OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、 ALL -->
<!-- 将所有日志输出到文件 -->
<logger name="*" minlevel="FATAL" maxlevel="FATAL" writeTo="info_file" />
<logger name="*" minlevel="Error" writeTo="error_file" />
</rules>
</nlog>