From 2b0a227732ecb1648eadd77f188b31180117c544 Mon Sep 17 00:00:00 2001 From: oneRain Date: Thu, 30 Apr 2020 16:04:35 +0800 Subject: [PATCH] chore: log --- Common/Common/Log/LCLogLevel.cs | 19 ++++++++++++ Common/Common/Log/LCLogger.cs | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Common/Common/Log/LCLogLevel.cs create mode 100644 Common/Common/Log/LCLogger.cs diff --git a/Common/Common/Log/LCLogLevel.cs b/Common/Common/Log/LCLogLevel.cs new file mode 100644 index 0000000..f43aaf5 --- /dev/null +++ b/Common/Common/Log/LCLogLevel.cs @@ -0,0 +1,19 @@ +namespace LeanCloud { + /// + /// 日志级别 + /// + public enum LCLogLevel { + /// + /// 调试级别 + /// + Debug, + /// + /// 警告级别 + /// + Warn, + /// + /// 错误级别 + /// + Error, + } +} diff --git a/Common/Common/Log/LCLogger.cs b/Common/Common/Log/LCLogger.cs new file mode 100644 index 0000000..1ffbcac --- /dev/null +++ b/Common/Common/Log/LCLogger.cs @@ -0,0 +1,51 @@ +using System; +using System.Text; + +namespace LeanCloud { + /// + /// 日志类 + /// + public static class LCLogger { + /// + /// 日志回调接口,方便开发者调试 + /// + /// The log delegate. + public static Action LogDelegate { + get; set; + } + + public static void Debug(string log) { + LogDelegate?.Invoke(LCLogLevel.Debug, log); + } + + public static void Debug(string format, params object[] args) { + LogDelegate?.Invoke(LCLogLevel.Debug, string.Format(format, args)); + } + + public static void Warn(string log) { + LogDelegate?.Invoke(LCLogLevel.Warn, log); + } + + public static void Warn(string format, params object[] args) { + LogDelegate?.Invoke(LCLogLevel.Warn, string.Format(format, args)); + } + + public static void Error(string log) { + LogDelegate?.Invoke(LCLogLevel.Error, log); + } + + public static void Error(string format, params object[] args) { + LogDelegate?.Invoke(LCLogLevel.Error, string.Format(format, args)); + } + + public static void Error(Exception e) { + StringBuilder sb = new StringBuilder(); + sb.Append(e.GetType()); + sb.Append("\n"); + sb.Append(e.Message); + sb.Append("\n"); + sb.Append(e.StackTrace); + Error(sb.ToString()); + } + } +}