2015-03-08 17:20:10 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
class Log
|
|
|
|
|
{
|
|
|
|
|
public enum Level
|
|
|
|
|
{
|
|
|
|
|
All,
|
|
|
|
|
Debug,
|
|
|
|
|
Production,
|
|
|
|
|
None,
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 23:01:05 -04:00
|
|
|
|
public Log(file logf, Level mode, int port)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
logFile = logf;
|
|
|
|
|
logMode = mode;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
Port = port;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:38:42 -04:00
|
|
|
|
public void Write(String line)
|
|
|
|
|
{
|
|
|
|
|
Write(line, Level.Debug);
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
public void Write(String line, Level lv)
|
|
|
|
|
{
|
2015-03-23 23:01:05 -04:00
|
|
|
|
String Line = String.Format("{1} - [{0}]: {2}", Port, getTime(), line);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
switch(logMode)
|
|
|
|
|
{
|
|
|
|
|
case Level.All:
|
|
|
|
|
if (lv == Level.All || lv == Level.Debug || lv == Level.Production)
|
|
|
|
|
Console.WriteLine(Line);
|
|
|
|
|
break;
|
|
|
|
|
case Level.Debug:
|
|
|
|
|
if (lv == Level.All || lv == Level.Debug)
|
|
|
|
|
Console.WriteLine(Line);
|
|
|
|
|
break;
|
|
|
|
|
case Level.Production:
|
|
|
|
|
if (lv == Level.Production)
|
|
|
|
|
Console.WriteLine(Line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logFile.Write(Line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string getTime()
|
|
|
|
|
{
|
|
|
|
|
return DateTime.Now.ToString("HH:mm:ss");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private file logFile;
|
|
|
|
|
private Level logMode;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
private int Port;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|