From bfcd2b437974f0717bfb71cd1a453205265858e6 Mon Sep 17 00:00:00 2001 From: oneRain Date: Wed, 4 Mar 2020 15:17:53 +0800 Subject: [PATCH] chore: namespace --- .gitignore | 2 ++ Common/Log/LogLevel.cs | 19 ++++++++++++++ Common/Log/Logger.cs | 40 ++++++++++++++++++++++++++++++ Test/Common.Test/AppRouterTest.cs | 12 ++++----- Test/Storage.Test/ACLTest.cs | 1 + Test/Storage.Test/CloudTest.cs | 1 + Test/Storage.Test/ExceptionTest.cs | 1 + Test/Storage.Test/FileTest.cs | 1 + Test/Storage.Test/ObjectTest.cs | 1 + Test/Storage.Test/OperationTest.cs | 1 + Test/Storage.Test/QueryTest.cs | 1 + Test/Storage.Test/RelationTest.cs | 1 + Test/Storage.Test/RoleTest.cs | 1 + Test/Storage.Test/SubClassTest.cs | 1 + Test/Storage.Test/UserTest.cs | 1 + 15 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 Common/Log/LogLevel.cs create mode 100644 Common/Log/Logger.cs diff --git a/.gitignore b/.gitignore index 3e759b7..3af01dd 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,5 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +!Common/Log/ diff --git a/Common/Log/LogLevel.cs b/Common/Log/LogLevel.cs new file mode 100644 index 0000000..5d9344c --- /dev/null +++ b/Common/Log/LogLevel.cs @@ -0,0 +1,19 @@ +namespace LeanCloud.Common { + /// + /// 日志级别 + /// + public enum LogLevel { + /// + /// 调试级别 + /// + Debug, + /// + /// 警告级别 + /// + Warn, + /// + /// 错误级别 + /// + Error, + } +} diff --git a/Common/Log/Logger.cs b/Common/Log/Logger.cs new file mode 100644 index 0000000..4e499d5 --- /dev/null +++ b/Common/Log/Logger.cs @@ -0,0 +1,40 @@ +using System; + +namespace LeanCloud.Common { + /// + /// 日志类 + /// + public static class Logger { + /// + /// 日志回调接口,方便开发者调试 + /// + /// The log delegate. + public static Action LogDelegate { + get; set; + } + + public static void Debug(string log) { + LogDelegate?.Invoke(LogLevel.Debug, log); + } + + public static void Debug(string format, params object[] args) { + LogDelegate?.Invoke(LogLevel.Debug, string.Format(format, args)); + } + + public static void Warn(string log) { + LogDelegate?.Invoke(LogLevel.Warn, log); + } + + public static void Warn(string format, params object[] args) { + LogDelegate?.Invoke(LogLevel.Warn, string.Format(format, args)); + } + + public static void Error(string log) { + LogDelegate?.Invoke(LogLevel.Error, log); + } + + public static void Error(string format, params object[] args) { + LogDelegate?.Invoke(LogLevel.Error, string.Format(format, args)); + } + } +} diff --git a/Test/Common.Test/AppRouterTest.cs b/Test/Common.Test/AppRouterTest.cs index acbc144..b037029 100644 --- a/Test/Common.Test/AppRouterTest.cs +++ b/Test/Common.Test/AppRouterTest.cs @@ -5,15 +5,15 @@ using LeanCloud.Common; namespace Common.Test { public class AppRouterTest { - static void Print(LeanCloud.LogLevel level, string info) { + static void Print(LogLevel level, string info) { switch (level) { - case LeanCloud.LogLevel.Debug: + case LogLevel.Debug: TestContext.Out.WriteLine($"[DEBUG] {info}"); break; - case LeanCloud.LogLevel.Warn: + case LogLevel.Warn: TestContext.Out.WriteLine($"[WARNING] {info}"); break; - case LeanCloud.LogLevel.Error: + case LogLevel.Error: TestContext.Out.WriteLine($"[ERROR] {info}"); break; default: @@ -24,12 +24,12 @@ namespace Common.Test { [SetUp] public void SetUp() { - LeanCloud.Logger.LogDelegate += Print; + Logger.LogDelegate += Print; } [TearDown] public void TearDown() { - LeanCloud.Logger.LogDelegate -= Print; + Logger.LogDelegate -= Print; } [Test] diff --git a/Test/Storage.Test/ACLTest.cs b/Test/Storage.Test/ACLTest.cs index 826891d..eb13f66 100644 --- a/Test/Storage.Test/ACLTest.cs +++ b/Test/Storage.Test/ACLTest.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using System.Threading.Tasks; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class ACLTest { diff --git a/Test/Storage.Test/CloudTest.cs b/Test/Storage.Test/CloudTest.cs index fdf5856..e723fbf 100644 --- a/Test/Storage.Test/CloudTest.cs +++ b/Test/Storage.Test/CloudTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class CloudTest { diff --git a/Test/Storage.Test/ExceptionTest.cs b/Test/Storage.Test/ExceptionTest.cs index 4097e6f..2341cb5 100644 --- a/Test/Storage.Test/ExceptionTest.cs +++ b/Test/Storage.Test/ExceptionTest.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class ExceptionTest { diff --git a/Test/Storage.Test/FileTest.cs b/Test/Storage.Test/FileTest.cs index 45916dc..187b7cb 100644 --- a/Test/Storage.Test/FileTest.cs +++ b/Test/Storage.Test/FileTest.cs @@ -3,6 +3,7 @@ using System; using System.Text; using System.Threading.Tasks; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class FileTest { diff --git a/Test/Storage.Test/ObjectTest.cs b/Test/Storage.Test/ObjectTest.cs index 17925f4..f94a39f 100644 --- a/Test/Storage.Test/ObjectTest.cs +++ b/Test/Storage.Test/ObjectTest.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; using System.Collections.Generic; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class ObjectTest { diff --git a/Test/Storage.Test/OperationTest.cs b/Test/Storage.Test/OperationTest.cs index 51951bf..ececc97 100644 --- a/Test/Storage.Test/OperationTest.cs +++ b/Test/Storage.Test/OperationTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class OperationTest { diff --git a/Test/Storage.Test/QueryTest.cs b/Test/Storage.Test/QueryTest.cs index 66dee5b..30c385a 100644 --- a/Test/Storage.Test/QueryTest.cs +++ b/Test/Storage.Test/QueryTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class QueryTest { diff --git a/Test/Storage.Test/RelationTest.cs b/Test/Storage.Test/RelationTest.cs index 6ac0904..433802b 100644 --- a/Test/Storage.Test/RelationTest.cs +++ b/Test/Storage.Test/RelationTest.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class RelationTest { diff --git a/Test/Storage.Test/RoleTest.cs b/Test/Storage.Test/RoleTest.cs index ccabcef..f11da18 100644 --- a/Test/Storage.Test/RoleTest.cs +++ b/Test/Storage.Test/RoleTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { [TestFixture] diff --git a/Test/Storage.Test/SubClassTest.cs b/Test/Storage.Test/SubClassTest.cs index a98c05f..9e1c994 100644 --- a/Test/Storage.Test/SubClassTest.cs +++ b/Test/Storage.Test/SubClassTest.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { internal class Hello : LCObject { diff --git a/Test/Storage.Test/UserTest.cs b/Test/Storage.Test/UserTest.cs index 2af6dc3..83a64e4 100644 --- a/Test/Storage.Test/UserTest.cs +++ b/Test/Storage.Test/UserTest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using LeanCloud.Storage; +using LeanCloud.Common; namespace LeanCloud.Test { public class UserTest {