Folder structure reconstruction
This commit is contained in:
74
MailServer/Logging/Logging.cs
Normal file
74
MailServer/Logging/Logging.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
//namespace Logging
|
||||
//{
|
||||
public class Logging
|
||||
{
|
||||
private static LoggingType[] ActiveLoggingTypes { get; set; }
|
||||
public string LogFolder { get; private set; }
|
||||
|
||||
public enum LoggingType
|
||||
{
|
||||
TRACE,
|
||||
ERROR,
|
||||
DEBUG,
|
||||
WARNING,
|
||||
INFO,
|
||||
ALL
|
||||
}
|
||||
|
||||
public Logging()
|
||||
{
|
||||
System.IO.Directory.GetCurrentDirectory();
|
||||
|
||||
ActiveLoggingTypes = new LoggingType[] { LoggingType.ALL };
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
|
||||
LogFolder = "/var/log/mail/mail.log";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void AddLogMessage(LoggingType messagetype, string message)
|
||||
{
|
||||
new TaskFactory(TaskScheduler.Current);
|
||||
new Task(() =>
|
||||
{
|
||||
if (CheckLoggingType(messagetype)) PrintToConsole(messagetype, message);
|
||||
}).Start();
|
||||
}
|
||||
|
||||
public static void AddException(Exception e)
|
||||
{
|
||||
AddLogMessage(LoggingType.ERROR, e.Message);
|
||||
}
|
||||
|
||||
private static bool CheckLoggingType(LoggingType lt)
|
||||
{
|
||||
if (ActiveLoggingTypes == null || ActiveLoggingTypes.Length < 1)
|
||||
{
|
||||
ActiveLoggingTypes = new LoggingType[1];
|
||||
ActiveLoggingTypes[0] = LoggingType.ALL;
|
||||
}
|
||||
bool found = false;
|
||||
foreach (LoggingType l in ActiveLoggingTypes)
|
||||
{
|
||||
if (l == lt || l == LoggingType.ALL)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private static void PrintToConsole(LoggingType lt, string message)
|
||||
{
|
||||
Console.WriteLine("[" + lt.ToString() + "]" + message);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user