120 lines
2.8 KiB
C#
120 lines
2.8 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
#if NOT_CLIENT
|
|
using NLog;
|
|
#endif
|
|
|
|
namespace ET
|
|
{
|
|
public static class Log
|
|
{
|
|
public const int TraceLevel = 1;
|
|
public const int DebugLevel = 2;
|
|
public const int InfoLevel = 3;
|
|
public const int WarningLevel = 4;
|
|
|
|
public static ILog ILog { get; }
|
|
|
|
static Log()
|
|
{
|
|
#if SERVER
|
|
ILog = new NLogger("Server");
|
|
#elif UNITY
|
|
ILog = new UnityLogger();
|
|
#elif ROBOT
|
|
ILog = new CommonLogger();
|
|
#endif
|
|
}
|
|
|
|
public static bool CheckLogLevel(int level)
|
|
{
|
|
if (Game.Options == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return Game.Options.LogLevel <= level;
|
|
}
|
|
|
|
public static Action<string> DebugCallback;
|
|
public static Action<string> ErrorCallback;
|
|
public static Action<string> InfoCallBack;
|
|
|
|
public static void Trace(string msg)
|
|
{
|
|
if (!CheckLogLevel(DebugLevel))
|
|
{
|
|
return;
|
|
}
|
|
DebugCallback?.Invoke(msg);
|
|
StackTrace st = new StackTrace(1, true);
|
|
ILog.Trace($"{msg}\n{st}");
|
|
}
|
|
|
|
public static void Debug(string msg)
|
|
{
|
|
if (!CheckLogLevel(DebugLevel))
|
|
{
|
|
return;
|
|
}
|
|
DebugCallback?.Invoke(msg);
|
|
ILog.Debug(msg);
|
|
}
|
|
|
|
public static void Info(string msg)
|
|
{
|
|
if (!CheckLogLevel(InfoLevel))
|
|
{
|
|
return;
|
|
}
|
|
|
|
InfoCallBack?.Invoke(msg);
|
|
ILog.Info(msg);
|
|
}
|
|
|
|
public static void TraceInfo(string msg)
|
|
{
|
|
if (!CheckLogLevel(InfoLevel))
|
|
{
|
|
return;
|
|
}
|
|
StackTrace st = new StackTrace(1, true);
|
|
InfoCallBack?.Invoke($"{msg}\n{st}");
|
|
ILog.Trace($"{msg}\n{st}");
|
|
}
|
|
|
|
public static void Warning(string msg)
|
|
{
|
|
if (!CheckLogLevel(WarningLevel))
|
|
{
|
|
return;
|
|
}
|
|
|
|
InfoCallBack?.Invoke($"{msg}");
|
|
ILog.Warning(msg);
|
|
}
|
|
|
|
public static void Error(string msg)
|
|
{
|
|
ErrorCallback?.Invoke(msg);
|
|
ILog.Error($"{msg}");
|
|
}
|
|
|
|
public static void ErrorDetail(string msg)
|
|
{
|
|
StackTrace st = new StackTrace(1, true);
|
|
ErrorCallback?.Invoke($"{msg}\n{st}");
|
|
ILog.Error($"{msg}\n{st}");
|
|
}
|
|
|
|
public static void Error(Exception e)
|
|
{
|
|
string str = e.ToString();
|
|
ErrorCallback?.Invoke(str);
|
|
ILog.Error(str);
|
|
}
|
|
}
|
|
} |