Преглед изворни кода

fix: 控制台输出颜色某些情况下没有恢复的问题

许俊杰 пре 3 година
родитељ
комит
ef998bbe88

+ 2 - 0
Admin.NET/Admin.NET.Core/Job/OnlineUserJob.cs

@@ -21,8 +21,10 @@ public class OnlineUserJob : IJob
         var rep = serviceScope.ServiceProvider.GetService<SqlSugarRepository<SysOnlineUser>>();
         await rep.AsDeleteable().ExecuteCommandAsync();
 
+        var originColor = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("【" + DateTime.Now + "】服务重启清空在线用户");
+        Console.ForegroundColor = originColor;
 
         // 缓存多租户
         await serviceScope.ServiceProvider.GetService<SysTenantService>().UpdateTenantCache();

+ 5 - 1
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -81,21 +81,25 @@ public static class SqlSugarSetup
         // 打印SQL语句
         db.Aop.OnLogExecuting = (sql, pars) =>
         {
+            var originColor = Console.ForegroundColor;
             if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
                 Console.ForegroundColor = ConsoleColor.Green;
             if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase))
-                Console.ForegroundColor = ConsoleColor.White;
+                Console.ForegroundColor = ConsoleColor.Yellow;
             if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
                 Console.ForegroundColor = ConsoleColor.Blue;
             Console.WriteLine("【" + DateTime.Now + "——执行SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, sql, pars) + "\r\n");
+            Console.ForegroundColor = originColor;
             App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
         };
         db.Aop.OnError = (ex) =>
         {
             if (ex.Parametres == null) return;
+            var originColor = Console.ForegroundColor;
             Console.ForegroundColor = ConsoleColor.Red;
             var pars = db.Utilities.SerializeObject(((SugarParameter[])ex.Parametres).ToDictionary(it => it.ParameterName, it => it.Value));
             Console.WriteLine("【" + DateTime.Now + "——错误SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
+            Console.ForegroundColor = originColor;
             App.PrintToMiniProfiler("SqlSugar", "Error", $"{ex.Message}{Environment.NewLine}{ex.Sql}{pars}{Environment.NewLine}");
         };