diff --git a/CLEditor.Core/CLEditor.Core.csproj b/CLEditor.Core/CLEditor.Core.csproj
index e8f02ab769616c32c51501e0d9eebfb57690f2fb..35a5a7164e9c7518353bfbb173dd66040fd02f21 100644
--- a/CLEditor.Core/CLEditor.Core.csproj
+++ b/CLEditor.Core/CLEditor.Core.csproj
@@ -68,7 +68,6 @@
-
@@ -84,6 +83,7 @@
+
diff --git a/CLEditor.Core/Debug.cs b/CLEditor.Core/Debug.cs
deleted file mode 100644
index 625393a96218868742086cb1645be5423e454f76..0000000000000000000000000000000000000000
--- a/CLEditor.Core/Debug.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using System;
-using System.Collections.ObjectModel;
-
-namespace CLEditor.Core
-{
- public static class Debug
- {
- public static ObservableCollection Messages { get; set; }
- public static void Warning(string message)
- {
- var log = new Log
- {
- Type = LogType.Warn,
- Message = message,
- };
- Messages.Add(log);
- }
-
- public static void Error(string message)
- {
- var log = new Log
- {
- Type = LogType.Error,
- Message = message,
- };
- Messages.Add(log);
- }
-
- public static void Error(Exception exception)
- {
- var log = new Log
- {
- Type = LogType.Error,
- Message = exception.Message,
- File = exception.Source,
- Status = exception.TargetSite.Name
- };
- Messages.Add(log);
- }
-
- public static void WriteLine(string message)
- {
- }
-
- static Debug()
- {
- Messages = new ObservableCollection();
- }
- }
-}
\ No newline at end of file
diff --git a/CLEditor.Core/Diagnostics/ConsoleLogListener.cs b/CLEditor.Core/Diagnostics/ConsoleLogListener.cs
index fa60e4c55ebbb4f609f5eebc3ab707e885e00996..fc3071f5dbc572fd3d1db91409e69bb845b6bb2b 100644
--- a/CLEditor.Core/Diagnostics/ConsoleLogListener.cs
+++ b/CLEditor.Core/Diagnostics/ConsoleLogListener.cs
@@ -71,7 +71,60 @@ namespace CLEditor.Core.Diagnostics
{
return;
}
+
+ EnsureConsole();
+
+#if C_PLATFORM_ANDROID
+ return;
+#else
+ var exceptionMsg = GetExceptionText(logMessage);
+#if C_PLATFORM_WINDOWS_DESKTOP || C_PLATFORM_UNIX
+ var initialColor = Console.ForegroundColor;
+
+ switch (logMessage.Type)
+ {
+ case LogMessageType.Debug:
+ Console.ForegroundColor = (ConsoleColor.DarkGray);
+ break;
+ case LogMessageType.Verbose:
+ Console.ForegroundColor = (ConsoleColor.Gray);
+ break;
+ case LogMessageType.Info:
+ Console.ForegroundColor = (ConsoleColor.Green);
+ break;
+ case LogMessageType.Warning:
+ Console.ForegroundColor = (ConsoleColor.Yellow);
+ break;
+ case LogMessageType.Error:
+ case LogMessageType.Fatal:
+ Console.ForegroundColor = (ConsoleColor.Red);
+ break;
+ }
+#endif
+
+ if (Debugger.IsAttached)
+ {
+ Debug.WriteLine(GetDefaultText(logMessage));
+ if (!string.IsNullOrEmpty(exceptionMsg))
+ {
+ Debug.WriteLine(logMessage);
+ }
+ }
+
+#if !C_PLATFORM_UWP
+ Console.WriteLine(GetDefaultText(logMessage));
+ if (!string.IsNullOrEmpty(exceptionMsg))
+ {
+ Console.WriteLine(exceptionMsg);
+ }
+#endif
+
+#if C_PLATFORM_WINDOWS_DESKTOP || C_PLATFORM_UNIX
+ Console.ForegroundColor = initialColor;
+#endif
+#endif
}
+
#if C_PLATFORM_WINDOWS_DESKTOP
private const int StdOutConsoleHandle = -11;
diff --git a/CLEditor.Core/Diagnostics/LogListener.cs b/CLEditor.Core/Diagnostics/LogListener.cs
index 544c232d13ca70c0241a571e2c370b530da335ac..86ff73bbcf354d0f943f694b803b16268aceb551 100644
--- a/CLEditor.Core/Diagnostics/LogListener.cs
+++ b/CLEditor.Core/Diagnostics/LogListener.cs
@@ -8,6 +8,7 @@ namespace CLEditor.Core.Diagnostics
///
public abstract class LogListener : IDisposable
{
+ private int logCountFlushLimit;
///
/// 获取日志消息计数
///
@@ -26,7 +27,7 @@ namespace CLEditor.Core.Diagnostics
///
public int LogCountFlushLimit
{
- get { return LogCountFlushLimit; }
+ get { return logCountFlushLimit; }
set
{
if (value <= 0)
@@ -34,7 +35,7 @@ namespace CLEditor.Core.Diagnostics
throw new ArgumentException("值必须大于0");
}
- LogCountFlushLimit = value;
+ logCountFlushLimit = value;
}
}
@@ -74,6 +75,37 @@ namespace CLEditor.Core.Diagnostics
return (logMessage.Type > LogMessageType.Info) || (LogMessageCount % LogCountFlushLimit) == 0;
}
+ ///
+ /// 获取特定日志消息的默认文本
+ ///
+ ///
+ ///
+ protected virtual string GetDefaultText(ILogMessage logMessage)
+ {
+ return TextFormatter(logMessage);
+ }
+
+ ///
+ /// 获取描述与特定日志消息关联的异常的文本
+ ///
+ ///
+ ///
+ [NotNull]
+ protected virtual string GetExceptionText([NotNull] ILogMessage message)
+ {
+ var serializableLogMessage = message as SerializableLogMessage;
+ if (serializableLogMessage != null)
+ {
+ return serializableLogMessage.ExceptionInfo?.ToString() ?? string.Empty;
+ }
+ var logMessage = message as LogMessage;
+ if (logMessage != null)
+ {
+ return logMessage.Exception?.ToString() ?? string.Empty;
+ }
+ throw new ArgumentException("不支持的日志消息.");
+ }
+
private void OnLogInternal([NotNull] ILogMessage logMessage)
{
OnLog(logMessage);
diff --git a/CLEditor.Core/Diagnostics/SerializableLogMessage.cs b/CLEditor.Core/Diagnostics/SerializableLogMessage.cs
new file mode 100644
index 0000000000000000000000000000000000000000..09958fbbbd8081ad1b2046168b968eee5bb6c50d
--- /dev/null
+++ b/CLEditor.Core/Diagnostics/SerializableLogMessage.cs
@@ -0,0 +1,27 @@
+using CLEditor.Core.Annotations;
+
+namespace CLEditor.Core.Diagnostics
+{
+ [DataContract]
+ public class SerializableLogMessage : ILogMessage
+ {
+ public string Module { get; set; }
+ public LogMessageType Type { get; set; }
+ public string Text { get; set; }
+ public ExceptionInfo ExceptionInfo { get; }
+
+ public SerializableLogMessage([NotNull] LogMessage message)
+ {
+ Module = message.Module;
+ Type = message.Type;
+ Text = message.Text;
+ ExceptionInfo = message.Exception != null ? new ExceptionInfo(message.Exception) : null;
+ }
+
+ public override string ToString()
+ {
+ return
+ $"{(Module != null ? $"[{Module}]: " : string.Empty)}{Type}: {Text}{(ExceptionInfo != null ? $". {ExceptionInfo.Message}" : string.Empty)}";
+ }
+ }
+}
\ No newline at end of file
diff --git a/CLEditor.Core/PropertyContainer.cs b/CLEditor.Core/PropertyContainer.cs
index 3c4bc1c965b69c3a58081361145c7c25e186e414..80ea740ecc8fb577a35ca60682583a3eea3736be 100644
--- a/CLEditor.Core/PropertyContainer.cs
+++ b/CLEditor.Core/PropertyContainer.cs
@@ -15,12 +15,6 @@ namespace CLEditor.Core
[DataContract]
public struct PropertyContainer : IDictionary, IReadOnlyDictionary
{
- private int _count;
- private ICollection _keys;
- private ICollection