1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-21 20:27:47 +00:00
project-meteor-server/FFXIVClassic Map Server/common/Log.cs

74 lines
2 KiB
C#
Raw Normal View History

2015-09-25 18:52:25 -04:00
using System;
using System.IO;
2015-09-25 18:52:25 -04:00
namespace FFXIVClassic_Map_Server.common
2015-09-25 18:52:25 -04:00
{
class Log
{
public enum LogType
{
Error = ConsoleColor.Red,
Debug = ConsoleColor.Yellow,
Info = ConsoleColor.Cyan,
Sql = ConsoleColor.Magenta,
Conn = ConsoleColor.Green,
Default = ConsoleColor.Gray
}
2015-09-25 18:52:25 -04:00
public static void error(String message)
{
log(message, LogType.Error);
2015-09-25 18:52:25 -04:00
}
public static void debug(String message)
{
#if DEBUG
log(message, LogType.Debug);
#endif
2015-09-25 18:52:25 -04:00
}
public static void info(String message)
{
log(message, LogType.Info);
2015-09-25 18:52:25 -04:00
}
public static void database(String message)
{
log(message, LogType.Sql);
2015-09-25 18:52:25 -04:00
}
public static void conn(String message)
{
log(message, LogType.Conn);
}
private static void log(String message, LogType type)
{
var timestamp = String.Format("[{0}] ", DateTime.Now.ToString("dd/MMM HH:mm:ss"));
var typestr = String.Format("[{0}] ", type.ToString().ToUpper());
Console.Write(timestamp);
Console.ForegroundColor = (ConsoleColor)type;
Console.Write(typestr);
2015-09-25 18:52:25 -04:00
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
message = message.Insert(0, typestr);
message = message.Insert(0, timestamp);
Directory.CreateDirectory(ConfigConstants.OPTIONS_LOGPATH);
try
{
File.AppendAllText(ConfigConstants.OPTIONS_LOGPATH + ConfigConstants.OPTIONS_LOGFILE, message + Environment.NewLine);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
2015-09-25 18:52:25 -04:00
}
}
}