You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
3 years ago
|
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();
|
||
|
}
|
||
|
}
|
||
|
}
|