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