This commit is contained in:
Razmoth
2023-08-21 21:45:57 +04:00
parent 6da2387c8c
commit 0bd3fa6db2
48 changed files with 967 additions and 510 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -34,4 +35,39 @@ namespace AssetStudio
Console.WriteLine("[{0}] {1}", loggerEvent, message);
}
}
public sealed class FileLogger : ILogger
{
private const string LogFileName = "log.txt";
private const string PrevLogFileName = "log_prev.txt";
private readonly object LockWriter = new object();
public StreamWriter Writer;
public FileLogger()
{
var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LogFileName);
var prevLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PrevLogFileName);
if (File.Exists(logPath))
{
File.Move(logPath, prevLogPath, true);
}
Writer = new StreamWriter(logPath, true) { AutoFlush = true };
}
~FileLogger()
{
Writer?.Dispose();
}
public void Log(LoggerEvent loggerEvent, string message, bool silent = false)
{
if (silent)
return;
lock (LockWriter)
{
Writer.WriteLine($"[{DateTime.Now}][{loggerEvent}] {message}");
}
}
}
}