Browse Source

添加日志输出到控制台自定义颜色模式,添加控制台输出且自定义颜色工具类

yuzhengyang 7 years ago
parent
commit
830e0048e9

BIN
Azylee.Utils/.vs/Azylee.Utils/v15/Server/sqlite3/storage.ide


+ 1 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -151,6 +151,7 @@
     <Compile Include="WindowsUtils\ClipboardUtils\ClipboardTool.cs" />
     <Compile Include="WindowsUtils\ClipboardUtils\ClipboardTool.cs" />
     <Compile Include="WindowsUtils\CMDUtils\CMDNetstatTool.cs" />
     <Compile Include="WindowsUtils\CMDUtils\CMDNetstatTool.cs" />
     <Compile Include="WindowsUtils\CMDUtils\CMDProcessTool.cs" />
     <Compile Include="WindowsUtils\CMDUtils\CMDProcessTool.cs" />
+    <Compile Include="WindowsUtils\ConsoleUtils\Ct.cs" />
     <Compile Include="WindowsUtils\HookUtils\KeyboardHook.cs" />
     <Compile Include="WindowsUtils\HookUtils\KeyboardHook.cs" />
     <Compile Include="WindowsUtils\HookUtils\KeyboardHookHelper.cs" />
     <Compile Include="WindowsUtils\HookUtils\KeyboardHookHelper.cs" />
     <Compile Include="WindowsUtils\HookUtils\UserActivityHook.cs" />
     <Compile Include="WindowsUtils\HookUtils\UserActivityHook.cs" />

+ 16 - 3
Azylee.Utils/Azylee.Core/LogUtils/SimpleLogUtils/Log.cs

@@ -103,13 +103,15 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
         /// 写出到控制台
         /// 写出到控制台
         /// </summary>
         /// </summary>
         /// <param name="type">类型</param>
         /// <param name="type">类型</param>
-        /// <param name="tag">标记</param>
         /// <param name="message">消息</param>
         /// <param name="message">消息</param>
-        private void Write(LogType type, string message)
+        /// <param name="color">炫彩颜色配置</param>
+        private void Write(LogType type, string message, ConsoleColor color = ConsoleColor.White)
         {
         {
             try
             try
             {
             {
-                Console.ForegroundColor = GetColor(type);
+                if (type == LogType.c) Console.ForegroundColor = color;//使用自定义配色
+                else Console.ForegroundColor = GetColor(type);//使用默认类型配色
+
                 Console.WriteLine(LOG_FORMAT, DateTime.Now.ToString(TIME_FORMAT), type.ToString(), message);
                 Console.WriteLine(LOG_FORMAT, DateTime.Now.ToString(TIME_FORMAT), type.ToString(), message);
             }
             }
             catch { }
             catch { }
@@ -241,6 +243,17 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
             if ((LogLevel & LogLevel.Error) == LogLevel.Error)
             if ((LogLevel & LogLevel.Error) == LogLevel.Error)
                 Write(LogType.e, msg.ToString());
                 Write(LogType.e, msg.ToString());
         }
         }
+        /// <summary>
+        /// 输出 Colorful (炫彩信息)
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="color"></param>
+        /// <param name="msg"></param>
+        public void c<T>(ConsoleColor color, T msg)
+        {
+            if ((LogLevel & LogLevel.Colorful) == LogLevel.Colorful)
+                Write(LogType.c, msg.ToString(), color);
+        }
         #endregion
         #endregion
     }
     }
 }
 }

+ 2 - 1
Azylee.Utils/Azylee.Core/LogUtils/SimpleLogUtils/LogLevel.cs

@@ -17,6 +17,7 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
         Information = 4,
         Information = 4,
         Warning = 8,
         Warning = 8,
         Error = 16,
         Error = 16,
-        All = Verbose | Debug | Information | Warning | Error,
+        Colorful = 32,
+        All = Verbose | Debug | Information | Warning | Error | Colorful,
     }
     }
 }
 }

+ 1 - 0
Azylee.Utils/Azylee.Core/LogUtils/SimpleLogUtils/LogType.cs

@@ -13,5 +13,6 @@ namespace Azylee.Core.LogUtils.SimpleLogUtils
         i,//information 一般提示性的消息
         i,//information 一般提示性的消息
         w,//warning 警告
         w,//warning 警告
         e,//error 错误信息
         e,//error 错误信息
+        c,//colorful 炫彩日志
     }
     }
 }
 }

+ 41 - 0
Azylee.Utils/Azylee.Core/WindowsUtils/ConsoleUtils/Ct.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Core.WindowsUtils.ConsoleUtils
+{
+    public static class Ct
+    {
+        public static void P(string value)
+        {
+            Console.Write(value);
+        }
+        public static void P(string value, ConsoleColor color)
+        {
+            Console.ForegroundColor = color;
+            Console.Write(value);
+        }
+        public static void P(string value, ConsoleColor color, ConsoleColor bgcolor)
+        {
+            Console.ForegroundColor = color;
+            Console.BackgroundColor = bgcolor;
+            Console.Write(value);
+        }
+        public static void Pl(string value)
+        {
+            Console.WriteLine(value);
+        }
+        public static void Pl(string value, ConsoleColor color)
+        {
+            Console.ForegroundColor = color;
+            Console.WriteLine(value);
+        }
+        public static void Pl(string value, ConsoleColor color, ConsoleColor bgcolor)
+        {
+            Console.ForegroundColor = color;
+            Console.BackgroundColor = bgcolor;
+            Console.WriteLine(value);
+        }
+    }
+}