mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-15 08:05:06 +00:00
41 lines
No EOL
1.1 KiB
C#
41 lines
No EOL
1.1 KiB
C#
using System.Text;
|
|
|
|
namespace Shared;
|
|
|
|
public class Logger {
|
|
public Logger(string name) {
|
|
Name = name;
|
|
}
|
|
|
|
public string Name { get; set; }
|
|
|
|
public void Info(string text) {
|
|
Console.ResetColor();
|
|
Console.Write(PrefixNewLines(text, $"Info [{Name}]"));
|
|
}
|
|
|
|
public void Warn(string text) {
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.Write(PrefixNewLines(text, $"Warn [{Name}]"));
|
|
}
|
|
|
|
public void Error(string text) {
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.Write(PrefixNewLines(text, $"Error [{Name}]"));
|
|
}
|
|
|
|
public void Error(Exception error) {
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.Write(PrefixNewLines(error.ToString(), $"Error [{Name}]"));
|
|
}
|
|
|
|
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();
|
|
}
|
|
} |