53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using System;
|
|
using System.Text;
|
|
using TouchSocket.Core;
|
|
|
|
namespace DragonSoul.Logic
|
|
{
|
|
public sealed class TouchLogger: TouchSocket.Core.ILog
|
|
{
|
|
public void Log(LogType logType, object source, string message, Exception exception)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff"));
|
|
stringBuilder.Append(" | ");
|
|
stringBuilder.Append(logType.ToString());
|
|
stringBuilder.Append(" | ");
|
|
stringBuilder.Append(message);
|
|
if (exception != null)
|
|
{
|
|
stringBuilder.Append(" | ");
|
|
stringBuilder.Append("【异常消息】:" + exception.Message);
|
|
stringBuilder.Append("【堆栈】:" + exception.StackTrace);
|
|
}
|
|
string s = stringBuilder.ToString();
|
|
switch (logType)
|
|
{
|
|
case LogType.None:
|
|
break;
|
|
case LogType.Trace:
|
|
__Log.InfoFile(s);
|
|
break;
|
|
case LogType.Debug:
|
|
__Log.InfoFile(s);
|
|
break;
|
|
case LogType.Info:
|
|
__Log.InfoFile(s);
|
|
break;
|
|
case LogType.Warning:
|
|
__Log.InfoFile(s);
|
|
break;
|
|
case LogType.Error:
|
|
__Log.ErrorFile(s);
|
|
break;
|
|
case LogType.Critical:
|
|
__Log.ErrorFile(s);
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof (logType), logType, null);
|
|
}
|
|
}
|
|
|
|
public LogType LogType { get; set; } = LogType.Error | LogType.Critical | LogType.Warning |LogType.Trace |LogType.Debug |LogType.Info;
|
|
}
|
|
} |