v0.90.10
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user