Просмотр исходного кода

😁增加控制台日志显示开关

zuohuaijun 2 лет назад
Родитель
Сommit
8bad70dfcf

+ 2 - 1
Admin.NET/Admin.NET.Application/Configuration/Logging.json

@@ -33,7 +33,8 @@
       "ReturnValueThreshold": 500, // 返回值字符串阈值,默认0全量输出
       "JsonBehavior": "None", // 是否输出Json,默认None(OnlyJson、All)
       "JsonIndented": false, // 是否格式化Json
-      "UseUtcTimestamp": false // 时间格式UTC、LOCAL
+      "UseUtcTimestamp": false, // 时间格式UTC、LOCAL
+      "ConsoleLog": true // 是否显示控制台日志
     }
   }
 }

+ 13 - 8
Admin.NET/Admin.NET.Core/Logging/LoggingSetup.cs

@@ -17,14 +17,6 @@ public static class LoggingSetup
     /// <param name="services"></param>
     public static void AddLoggingSetup(this IServiceCollection services)
     {
-        // 控制台日志格式化
-        services.AddConsoleFormatter(options =>
-        {
-            options.DateFormat = "yyyy-MM-dd HH:mm:ss(zzz) dddd";
-            //options.WithTraceId = true; // 显示线程Id
-            //options.WithStackFrame = true; // 显示程序集
-        });
-
         // 日志监听
         services.AddMonitorLogging(options =>
         {
@@ -32,6 +24,19 @@ public static class LoggingSetup
             options.IgnorePropertyTypes = new[] { typeof(byte[]) };
         });
 
+        // 控制台日志
+        var consoleLog = App.GetConfig<bool>("Logging:Monitor:ConsoleLog", true);
+        services.AddConsoleFormatter(options =>
+        {
+            options.DateFormat = "yyyy-MM-dd HH:mm:ss(zzz) dddd";
+            //options.WithTraceId = true; // 显示线程Id
+            //options.WithStackFrame = true; // 显示程序集
+            options.WriteFilter = (logMsg) =>
+            {
+                return consoleLog;
+            };
+        });
+
         // 日志写入文件
         if (App.GetConfig<bool>("Logging:File:Enabled", true))
         {