dotnet-core_mail-server/MailServer/MailServer/Logging/Logging.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2016-11-23 21:32:40 +00:00
using System;
2016-11-26 11:11:27 +00:00
//namespace Logging
//{
2016-11-23 21:32:40 +00:00
public class Logging
{
private static LoggingType[] _ActiveLoggingTypes { get; set; }
public enum LoggingType
{
TRACE,
ERROR,
DEBUG,
WARNING,
INFO,
ALL
}
2016-11-26 11:11:27 +00:00
public static void AddLogMessage(LoggingType messagetype, string message)
2016-11-23 21:32:40 +00:00
{
if(CheckLoggingType(messagetype)) PrintToConsole(messagetype, message);
}
2016-11-26 11:11:27 +00:00
public static void AddException(Exception e)
{
AddLogMessage(LoggingType.ERROR, e.Message);
}
2016-11-23 21:32:40 +00:00
private static bool CheckLoggingType(LoggingType lt){
2016-11-26 11:11:27 +00:00
if (_ActiveLoggingTypes == null ||_ActiveLoggingTypes.Length < 1) {
2016-11-23 21:32:40 +00:00
_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);
}
}
2016-11-26 11:11:27 +00:00
//}