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

73 lines
2 KiB
C#
Raw Normal View History

2015-09-25 18:52:25 -04:00
using System;
using System.IO;
using System.Text;
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
{
Status = ConsoleColor.Green,
Sql = ConsoleColor.Magenta,
Info = ConsoleColor.White,
Debug = ConsoleColor.Cyan,
Error = ConsoleColor.Red
}
public static void Status(String message)
2015-09-25 18:52:25 -04:00
{
LogFile(message, LogType.Status);
2015-09-25 18:52:25 -04:00
}
public static void Sql(String message)
{
LogFile(message, LogType.Sql);
2015-09-25 18:52:25 -04:00
}
public static void Info(String message)
2015-09-25 18:52:25 -04:00
{
LogFile(message, LogType.Info);
2015-09-25 18:52:25 -04:00
}
public static void Debug(String message)
2015-09-25 18:52:25 -04:00
{
#if DEBUG
LogFile(message, LogType.Debug);
#endif
2015-09-25 18:52:25 -04:00
}
public static void Error(String message)
2015-09-25 18:52:25 -04:00
{
LogFile(message, LogType.Error);
}
private static void LogFile(String message, LogType type)
{
string timestamp = String.Format("[{0}]", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
string messageType = String.Format("[{0}] ", type.ToString().ToUpper());
Console.WriteLine(timestamp);
Console.ForegroundColor = (ConsoleColor)type;
Console.Write(messageType);
Console.ResetColor();
Console.Write(message);
StringBuilder sb = new StringBuilder();
sb.AppendLine(String.Format("{0}{1}{2}", timestamp, messageType, message));
if (!Directory.Exists(ConfigConstants.OPTIONS_LOGPATH))
{
Directory.CreateDirectory(ConfigConstants.OPTIONS_LOGPATH);
}
using (FileStream fs = new FileStream(Path.Combine(ConfigConstants.OPTIONS_LOGPATH, ConfigConstants.OPTIONS_LOGFILE), FileMode.Append, FileAccess.Write))
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(sb.ToString());
}
2015-09-25 18:52:25 -04:00
}
}
}