using EC.Entity.BaseData; using EC.Util.NetLogger; using EC.Utils.SocketHelper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EC.NetLogger { public class TCPLoggerManger { static SocketClient Socket_Client = null; public static bool Init(string ip, int port) { Socket_Client = new SocketClient(ip, port); return Socket_Client.Start(); } public static void SendCommandLogger(CommandJsonDataEntity entity) { Task.Factory.StartNew(() => { if (Socket_Client == null) return ; if (entity == null) return ; string sendStr = NetLoggerKey.CommandKey + JsonUnit.ObjectToJson(entity); bool send= Socket_Client.SendToService(sendStr); if (!send) { LogUnit.Error("发送网络日志失败"); } }); } public static void SendFileLogger(CommandJsonDataEntity entity) { Task.Factory.StartNew(() => { if (Socket_Client == null) return; if (entity == null) return; string sendStr = NetLoggerKey.CommandKey + JsonUnit.ObjectToJson(entity); bool send = Socket_Client.SendToService(sendStr); if (!send) { LogUnit.Error("发送网络日志失败"); } }); } public static void Stop() { Socket_Client?.Stop(); } } }