47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
namespace DaggerFramework.Utils
|
|
{
|
|
public class Logger
|
|
{
|
|
public static Action<string, LogType>? OnLog;
|
|
public Logger(string className)
|
|
{
|
|
_className = className;
|
|
}
|
|
public void Info(object what)
|
|
{
|
|
LogType logType = LogType.Info;
|
|
string message = $"({DateFormat}) [{logType.ToString().ToUpper()}/{_className}] {what}";
|
|
LogConsole(message);
|
|
OnLog?.Invoke(message, logType);
|
|
}
|
|
|
|
public void Warn(object what)
|
|
{
|
|
LogType logType = LogType.Warn;
|
|
string message = $"({DateFormat}) [{logType.ToString().ToUpper()}/{_className}] {what}";
|
|
LogConsole(message);
|
|
OnLog?.Invoke(message, logType);
|
|
}
|
|
|
|
public void Error(object what)
|
|
{
|
|
LogType logType = LogType.Error;
|
|
string message = $"({DateFormat}) [{logType.ToString().ToUpper()}/{_className}] {what}";
|
|
LogConsole(message);
|
|
OnLog?.Invoke(message, logType);
|
|
}
|
|
|
|
|
|
private static string DateFormat => $"{DateTime.Now:t}";
|
|
|
|
private static void LogConsole(string what) => Console.WriteLine(what);
|
|
private readonly string _className;
|
|
}
|
|
|
|
public enum LogType
|
|
{
|
|
Info,
|
|
Warn,
|
|
Error
|
|
}
|
|
} |