使用责任链编写Logger

Signed-off-by: Eicy <im@crash.work>
This commit is contained in:
2024-12-21 01:02:31 +08:00
parent f05dce81a0
commit 7bacff5e24
8 changed files with 229 additions and 0 deletions

33
Logger/AbstractLogger.cs Normal file
View File

@@ -0,0 +1,33 @@
using Debugger;
using Shrink.Config;
namespace Shrink.Logger;
public abstract class AbstractLogger
{
private AbstractLogger? _nextLogger;
protected LogLevel LogLevel;
public void SetNextLogger(AbstractLogger? nextLogger)
{
_nextLogger = nextLogger;
}
public void LogMessage(string data, string eventName, LogLevel level, MsgType msgType, uint uin, string message)
{
//LogLevel = Info
//Config设置为Only Fatal
if (LogLevel == level)
{
//Info 3
//Fatal 0
if (LogLevel > Configuration.Instance.Config.LogLevel) return;
Log(data, eventName, msgType, uin, message);
LogManager.Instance.IsSent = true;
}
else
_nextLogger?.LogMessage(data, eventName, level, msgType, uin, message);
}
protected abstract void Log(string data, string eventName, MsgType msgType, uint uin, string message);
}