csharp-sdk-upm/Common/Log/LCLogger.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2020-03-04 15:17:53 +08:00
using System;
using System.Text;
2020-03-04 15:17:53 +08:00
namespace LeanCloud.Common {
/// <summary>
/// 日志类
/// </summary>
2020-03-10 16:54:50 +08:00
public static class LCLogger {
2020-03-04 15:17:53 +08:00
/// <summary>
/// 日志回调接口,方便开发者调试
/// </summary>
/// <value>The log delegate.</value>
2020-03-10 16:54:50 +08:00
public static Action<LCLogLevel, string> LogDelegate {
2020-03-04 15:17:53 +08:00
get; set;
}
public static void Debug(string log) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Debug, log);
2020-03-04 15:17:53 +08:00
}
public static void Debug(string format, params object[] args) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Debug, string.Format(format, args));
2020-03-04 15:17:53 +08:00
}
public static void Warn(string log) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Warn, log);
2020-03-04 15:17:53 +08:00
}
public static void Warn(string format, params object[] args) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Warn, string.Format(format, args));
2020-03-04 15:17:53 +08:00
}
public static void Error(string log) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Error, log);
2020-03-04 15:17:53 +08:00
}
public static void Error(string format, params object[] args) {
2020-03-10 16:54:50 +08:00
LogDelegate?.Invoke(LCLogLevel.Error, string.Format(format, args));
2020-03-04 15:17:53 +08:00
}
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());
}
2020-03-04 15:17:53 +08:00
}
}