mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
43 lines
912 B
C#
43 lines
912 B
C#
using System.Text;
|
|
|
|
namespace AssetRipper.Import.Logging;
|
|
|
|
public class FileLogger : FileLoggerBase
|
|
{
|
|
private readonly StringBuilder stringBuilder = new();
|
|
|
|
public FileLogger() : base() { }
|
|
|
|
/// <param name="filePath">The absolute path to the log file</param>
|
|
public FileLogger(string filePath) : base(filePath) { }
|
|
|
|
public sealed override void Log(LogType type, LogCategory category, string message)
|
|
{
|
|
stringBuilder.Clear();
|
|
|
|
if (category != LogCategory.None)
|
|
{
|
|
stringBuilder.Append($"{category.ToString()} ");
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case LogType.Warning:
|
|
case LogType.Error:
|
|
stringBuilder.Append($"[{type.ToString()}] ");
|
|
break;
|
|
}
|
|
stringBuilder.Append(": ");
|
|
stringBuilder.Append(message);
|
|
stringBuilder.Append(Environment.NewLine);
|
|
try
|
|
{
|
|
File.AppendAllText(filePath, stringBuilder.ToString());
|
|
}
|
|
catch (IOException)
|
|
{
|
|
//Could not log to file
|
|
}
|
|
}
|
|
}
|