58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace KattekerCreator.Helper
|
|
{
|
|
public static class Log
|
|
{
|
|
private const string Info = "INFO";
|
|
private const string Error = "ERROR";
|
|
|
|
public static void WriteInfoLine(string text)
|
|
{
|
|
using (new ConsoleWithOtherColor())
|
|
{
|
|
ConsoleWithOtherColor.WriteLine($"{Info} [{DateTime.Now:G}] {text}");
|
|
}
|
|
}
|
|
|
|
public static void WriteErrorLine(string text)
|
|
{
|
|
using (new ConsoleWithOtherColor(ConsoleColor.DarkRed))
|
|
{
|
|
ConsoleWithOtherColor.WriteLine($"{Error} [{DateTime.Now:G}] {text}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ConsoleWithOtherColor : IDisposable
|
|
{
|
|
public ConsoleWithOtherColor()
|
|
{
|
|
}
|
|
|
|
private readonly ConsoleColor? _defaultColor;
|
|
|
|
public ConsoleWithOtherColor(ConsoleColor color)
|
|
{
|
|
_defaultColor = Console.ForegroundColor;
|
|
Console.ForegroundColor = color;
|
|
}
|
|
|
|
public static void WriteLine(string text)
|
|
{
|
|
Console.WriteLine(text);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
private void Dispose(bool disposing)
|
|
{
|
|
if (!disposing) return;
|
|
if (_defaultColor != null) Console.ForegroundColor = _defaultColor.Value;
|
|
}
|
|
}
|
|
} |