mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
48 lines
1.0 KiB
C#
48 lines
1.0 KiB
C#
using Netch.Interfaces;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace Netch.Models.Loggers
|
|
{
|
|
public class FileLogger : ILogger
|
|
{
|
|
public string LogFile { get; set; } = Path.Combine(Global.NetchDir, "logging\\application.log");
|
|
|
|
private readonly object _fileLock = new();
|
|
|
|
public void Info(string text)
|
|
{
|
|
Write(text, LogLevel.INFO);
|
|
}
|
|
|
|
public void Warning(string text)
|
|
{
|
|
Write(text, LogLevel.WARNING);
|
|
}
|
|
|
|
public void Error(string text)
|
|
{
|
|
Write(text, LogLevel.ERROR);
|
|
}
|
|
|
|
public void Write(string text, LogLevel logLevel)
|
|
{
|
|
var contents = $@"[{DateTime.Now}][{logLevel.ToString()}] {text}{Constants.EOF}";
|
|
|
|
lock (_fileLock)
|
|
File.AppendAllText(LogFile, contents);
|
|
}
|
|
|
|
public void Debug(string s)
|
|
{
|
|
#if DEBUG
|
|
Write(s, LogLevel.DEBUG);
|
|
#endif
|
|
}
|
|
|
|
public void ShowLog()
|
|
{
|
|
Utils.Utils.Open(LogFile);
|
|
}
|
|
}
|
|
} |