You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

#if !NET20
using System;
namespace Apewer.WebSocket
{
/// <summary></summary>
public enum LogLevel
{
/// <summary></summary>
Debug = 0,
/// <summary></summary>
Info = 1,
/// <summary></summary>
Warn = 2,
/// <summary></summary>
Error = 3
}
internal class WebSocketLog
{
public static LogLevel Level = LogLevel.Info;
public static Logger Logger { get; set; }
public static Action<LogLevel, string, Exception> LogAction = (level, message, ex) =>
{
if (level < Level) return;
switch (level)
{
case LogLevel.Debug:
Logger?.Debug(typeof(WebSocketLog), message);
break;
case LogLevel.Info:
Logger?.Text(typeof(WebSocketLog), message);
break;
case LogLevel.Warn:
Logger?.Warning(typeof(WebSocketLog), message);
break;
case LogLevel.Error:
Logger?.Error(typeof(WebSocketLog), message);
break;
}
};
public static void Warn(string message, Exception ex = null)
{
LogAction(LogLevel.Warn, message, ex);
}
public static void Error(string message, Exception ex = null)
{
LogAction(LogLevel.Error, message, ex);
}
public static void Debug(string message, Exception ex = null)
{
LogAction(LogLevel.Debug, message, ex);
}
public static void Info(string message, Exception ex = null)
{
LogAction(LogLevel.Info, message, ex);
}
}
}
#endif