2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace CoopServer
|
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
public class Logging
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
private static readonly object Lock = new();
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
public static void Info(string message)
|
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
lock (Lock)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
string msg = string.Format("[{0}] [INFO] {1}", Date(), message);
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
using StreamWriter sw = new("log.txt", true);
|
|
|
|
|
sw.WriteLine(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Warning(string message)
|
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
lock (Lock)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
string msg = string.Format("[{0}] [WARNING] {1}", Date(), message);
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
using StreamWriter sw = new("log.txt", true);
|
|
|
|
|
sw.WriteLine(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Error(string message)
|
|
|
|
|
{
|
2021-08-20 17:28:13 +02:00
|
|
|
|
lock (Lock)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
string msg = string.Format("[{0}] [ERROR] {1}", Date(), message);
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
using StreamWriter sw = new("log.txt", true);
|
|
|
|
|
sw.WriteLine(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Debug(string message)
|
|
|
|
|
{
|
|
|
|
|
if (!Server.MainSettings.DebugMode)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 17:28:13 +02:00
|
|
|
|
lock (Lock)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
string msg = string.Format("[{0}] [DEBUG] {1}", Date(), message);
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Blue;
|
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
using StreamWriter sw = new("log.txt", true);
|
|
|
|
|
sw.WriteLine(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static string Date()
|
|
|
|
|
{
|
|
|
|
|
return DateTime.Now.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|