2022-05-05 14:46:04 +02:00
|
|
|
|
namespace Logging
|
2022-05-05 02:01:05 +02:00
|
|
|
|
{
|
|
|
|
|
public class Logger
|
|
|
|
|
{
|
|
|
|
|
private LogType logType;
|
|
|
|
|
private string logfilepath;
|
2022-05-05 16:00:56 +02:00
|
|
|
|
private loglevel level;
|
|
|
|
|
public Logger(LogType type, loglevel level)
|
2022-05-05 02:01:05 +02:00
|
|
|
|
{
|
|
|
|
|
this.logType = type;
|
|
|
|
|
this.logfilepath = "";
|
2022-05-05 16:00:56 +02:00
|
|
|
|
this.level = level;
|
2022-05-05 02:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 16:00:56 +02:00
|
|
|
|
public Logger(LogType type, loglevel level, string path)
|
2022-05-05 02:01:05 +02:00
|
|
|
|
{
|
|
|
|
|
this.logType = type;
|
|
|
|
|
this.logfilepath = path;
|
2022-05-05 16:00:56 +02:00
|
|
|
|
this.level = level;
|
2022-05-05 02:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 16:00:56 +02:00
|
|
|
|
public void log(loglevel type, string message, params object[] ?replace)
|
2022-05-05 02:01:05 +02:00
|
|
|
|
{
|
2022-05-05 16:00:56 +02:00
|
|
|
|
if(type >= this.level)
|
2022-05-05 02:01:05 +02:00
|
|
|
|
{
|
2022-05-05 16:25:42 +02:00
|
|
|
|
string header = string.Format("{0} {1} {2}: ", DateTime.Now.ToLocalTime().ToShortDateString(), DateTime.Now.ToLocalTime().ToLongTimeString(), type.ToString());
|
2022-05-05 16:00:56 +02:00
|
|
|
|
switch (this.logType)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Console:
|
|
|
|
|
Console.WriteLine(string.Format(header + message, replace));
|
|
|
|
|
break;
|
|
|
|
|
case LogType.Logfile:
|
|
|
|
|
File.WriteAllText(this.logfilepath, string.Format(header + message, replace));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-05 02:01:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum LogType { Console, Logfile }
|
2022-05-05 16:00:56 +02:00
|
|
|
|
public enum loglevel : ushort { DEBUG = 0, INFO = 1, ERROR = 2 };
|
2022-05-05 02:01:05 +02:00
|
|
|
|
}
|