feat: add logger to udpclient

This commit is contained in:
2025-05-20 09:34:26 +08:00
parent 487e7c114a
commit 07eb606324
3 changed files with 21 additions and 0 deletions

View File

@@ -9,6 +9,8 @@ using WebProtocol;
/// </summary>
public class UDPClientPool
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static IPAddress localhost = IPAddress.Parse("127.0.0.1");
/// <summary>
@@ -58,6 +60,9 @@ public class UDPClientPool
var sendLen = socket.SendTo(buf, endPoint);
socket.Close();
logger.Debug($"UDP socket send bytes to device {endPoint.Address.ToString()}:{endPoint.Port.ToString()}:");
logger.Debug($" Original Data: {BitConverter.ToString(buf).Replace("-", " ")}");
if (sendLen == buf.Length) { return true; }
else { return false; }
}
@@ -86,6 +91,10 @@ public class UDPClientPool
var sendLen = socket.SendTo(sendBytes, endPoint);
socket.Close();
logger.Debug($"UDP socket send address package to device {endPoint.Address.ToString()}:{endPoint.Port.ToString()}:");
logger.Debug($" Original Data: {BitConverter.ToString(pkg.ToBytes()).Replace("-", " ")}");
logger.Debug($" Decoded Data: {pkg.ToString()}");
if (sendLen == sendBytes.Length) { return true; }
else { return false; }
}
@@ -115,6 +124,9 @@ public class UDPClientPool
var sendLen = socket.SendTo(sendBytes, endPoint);
socket.Close();
logger.Debug($"UDP socket send data package to device {endPoint.Address.ToString()}:{endPoint.Port.ToString()}:");
logger.Debug($" Original Data: {BitConverter.ToString(pkg.ToBytes()).Replace("-", " ")}");
if (sendLen == sendBytes.Length) { return true; }
else { return false; }
}