dotnet-core_mail-server/MailServer/MailServer/Logging/Logging.cs
2016-11-26 12:11:27 +01:00

54 lines
1.3 KiB
C#

using System;
//namespace Logging
//{
public class Logging
{
private static LoggingType[] _ActiveLoggingTypes { get; set; }
public enum LoggingType
{
TRACE,
ERROR,
DEBUG,
WARNING,
INFO,
ALL
}
public static void AddLogMessage(LoggingType messagetype, string message)
{
if(CheckLoggingType(messagetype)) PrintToConsole(messagetype, message);
}
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);
}
}
//}