2022-04-28 03:32:52 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Shared;
|
2021-11-29 04:04:34 +00:00
|
|
|
|
|
|
|
|
|
public class Logger {
|
|
|
|
|
public Logger(string name) {
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 19:45:58 +00:00
|
|
|
|
public string Name { get; set; }
|
2022-02-10 01:44:50 +00:00
|
|
|
|
|
2021-11-29 04:04:34 +00:00
|
|
|
|
public void Info(string text) {
|
|
|
|
|
Console.ResetColor();
|
2022-04-28 03:33:48 +00:00
|
|
|
|
Console.Write(PrefixNewLines(text, $"Info [{Name}]"));
|
2021-11-29 04:04:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Warn(string text) {
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
2022-04-28 03:33:48 +00:00
|
|
|
|
Console.Write(PrefixNewLines(text, $"Warn [{Name}]"));
|
2021-11-29 04:04:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(string text) {
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
2022-04-28 03:33:48 +00:00
|
|
|
|
Console.Write(PrefixNewLines(text, $"Error [{Name}]"));
|
2022-04-28 03:32:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Error(Exception error) {
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
2022-04-28 03:33:48 +00:00
|
|
|
|
Console.Write(PrefixNewLines(error.ToString(), $"Error [{Name}]"));
|
2022-04-28 03:32:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string PrefixNewLines(string text, string prefix) {
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
foreach (string str in text.Split('\n'))
|
|
|
|
|
builder
|
|
|
|
|
.Append(prefix)
|
|
|
|
|
.Append(' ')
|
|
|
|
|
.AppendLine(str);
|
|
|
|
|
return builder.ToString();
|
2021-11-29 04:04:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|