2015-07-06 14:29:34 +00:00
|
|
|
|
using System; //Copyright (c) NorbiPeti 2015 - See LICENSE file
|
2015-03-26 19:36:18 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MSGer.tk
|
|
|
|
|
{
|
|
|
|
|
public class Logging
|
|
|
|
|
{
|
|
|
|
|
public enum LogType
|
|
|
|
|
{
|
|
|
|
|
Network
|
|
|
|
|
}
|
|
|
|
|
public static void Log(string message, LogType logtype) //2014.12.31.
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists("logs"))
|
|
|
|
|
Directory.CreateDirectory("logs");
|
|
|
|
|
string path;
|
|
|
|
|
switch (logtype)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Network:
|
|
|
|
|
path = "network";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new NotImplementedException("Log type not implemented.");
|
|
|
|
|
}
|
|
|
|
|
string finaltext = "[" + Process.GetCurrentProcess().Id + ": " + Thread.CurrentThread.Name + " | " + DateTime.Now.ToString("yyyy.MM.dd. HH:mm:ss") + "] " + message + Environment.NewLine;
|
|
|
|
|
Console.WriteLine(logtype.ToString() + " - " + finaltext);
|
2015-07-06 11:04:54 +00:00
|
|
|
|
while (true)
|
2015-03-26 19:36:18 +00:00
|
|
|
|
{
|
|
|
|
|
bool retry = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.AppendAllText("logs\\" + path + ".txt", finaltext);
|
|
|
|
|
}
|
2015-07-06 11:04:54 +00:00
|
|
|
|
catch (IOException)
|
2015-03-26 19:36:18 +00:00
|
|
|
|
{
|
|
|
|
|
retry = true;
|
|
|
|
|
}
|
|
|
|
|
if (!retry)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|