1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-22 12:47:46 +00:00
project-meteor-server/FFXIVClassic Map Server/common/Log.cs
Tahir Akhlaq 8b93abe86e servers now log (almost) everything to file
- regex'd in mysqlexception logging
- servers can now specify server_port, log_path, log_file
- added scripts to import/export all tables (exporting will export a handful of garbage table names, open and check for structure before deleting)
- fixed packet logging (thanks deviltti)
2016-06-09 19:48:06 +01:00

73 lines
2 KiB
C#

using System;
using System.IO;
namespace FFXIVClassic_Map_Server.common
{
class Log
{
public enum LogType
{
Error = ConsoleColor.Red,
Debug = ConsoleColor.Yellow,
Info = ConsoleColor.Cyan,
Sql = ConsoleColor.Magenta,
Conn = ConsoleColor.Green,
Default = ConsoleColor.Gray
}
public static void error(String message)
{
log(message, LogType.Error);
}
public static void debug(String message)
{
#if DEBUG
log(message, LogType.Debug);
#endif
}
public static void info(String message)
{
log(message, LogType.Info);
}
public static void database(String message)
{
log(message, LogType.Sql);
}
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);
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;
}
}
}
}