/// <summary> /// Log current log levels /// </summary> public static void WriteLogLevels(IPBanCore.LogLevel level = LogLevel.Warn) { if (instance != null) { Logger.Write(level, IPBanService.UtcNow, "Log levels: {0},{1},{2},{3},{4},{5}", instance.IsFatalEnabled, instance.IsErrorEnabled, instance.IsWarnEnabled, instance.IsInfoEnabled, instance.IsDebugEnabled, instance.IsTraceEnabled); } }
/// <summary> /// Write to the log /// </summary> /// <param name="level">Log level</param> /// <param name="ts">Timestamp</param> /// <param name="text">Text with format</param> /// <param name="args">Format args</param> private static void Write(IPBanCore.LogLevel level, DateTime ts, string text, params object[] args) { try { #if DEBUG if (level == LogLevel.Error || level == LogLevel.Critical || level == LogLevel.Fatal) { // System.Diagnostics.Debugger.Break(); } #endif //timeSource.CurrentTime = ts; nlogInstance?.Log(GetNLogLevel(level), text, args); } catch { } }
/// <summary> /// Map IPBan log level to NLog log level /// </summary> /// <param name="logLevel">IPBan log level</param> /// <returns>NLog log level</returns> public static NLog.LogLevel GetNLogLevel(IPBanCore.LogLevel logLevel) { switch (logLevel) { case IPBanCore.LogLevel.Critical: return(NLog.LogLevel.Fatal); case IPBanCore.LogLevel.Debug: return(NLog.LogLevel.Debug); case IPBanCore.LogLevel.Error: return(NLog.LogLevel.Error); case IPBanCore.LogLevel.Information: return(NLog.LogLevel.Info); case IPBanCore.LogLevel.Trace: return(NLog.LogLevel.Trace); case IPBanCore.LogLevel.Warning: return(NLog.LogLevel.Warn); default: return(NLog.LogLevel.Off); } }
/// <summary> /// Write to the log /// </summary> /// <param name="level">Log level</param> /// <param name="text">Text with format</param> /// <param name="args">Format args</param> public static void Write(IPBanCore.LogLevel level, string text, params object[] args) { Write(level, IPBanService.UtcNow, text, args); }