using System; using System.Diagnostics; using System.Reflection; using NLog; namespace ChaosBot { public static class LoggingFacade { private static ILogger GetLogger() { return Program.GetLogger(); } public static bool IsTraceEnabled => GetLogger().IsTraceEnabled; public static bool IsDebugEnabled => GetLogger().IsDebugEnabled; public static bool IsInfoEnabled => GetLogger().IsInfoEnabled; public static bool IsWarnEnabled => GetLogger().IsWarnEnabled; public static bool IsErrorEnabled => GetLogger().IsErrorEnabled; public static bool IsFatalEnabled => GetLogger().IsFatalEnabled; public static void Trace(object value) { GetLogger().Trace(value); } public static void Debug(object value) { GetLogger().Debug(value); } public static void Info(object value) { GetLogger().Info(value); } public static void Warn(object value) { GetLogger().Warn(value); } public static void Error(object value) { GetLogger().Error(value); } public static void Fatal(object value) { GetLogger().Fatal(value); } public static void Exception(Exception ex) { MethodBase method = new StackFrame(1).GetMethod(); Error($"{method?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); Debug($"{method?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}"); } } }