Browse Source

读取和初始化LogLevel

Jeremy 2 years ago
parent
commit
cc91b112d8
2 changed files with 20 additions and 8 deletions
  1. 9 6
      Config/ConfigurationManager.cs
  2. 11 2
      Config/LogSettings.cs

+ 9 - 6
Config/ConfigurationManager.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using WingServerCommon.Config.Parameters;
 
@@ -15,24 +16,24 @@ namespace WingServerCommon.Config
         /// </summary>
         /// <value></value>
         public static string Host { get; private set; }
-        
+
         /// <summary>
         /// Indicates the server will be deployed as distributed system
         /// </summary>
         /// <value></value>
-        public static bool IsDistributed {get;set;} 
+        public static bool IsDistributed { get; set; }
 
         /// <summary>
         /// Indicates the server is master
         /// </summary>
         /// <value></value>
-        public static bool IsMaster {get;set;}
-        
+        public static bool IsMaster { get; set; }
+
         /// <summary>
         /// The master server url
         /// </summary>
         /// <value></value>
-        public static string MasterUrl {get;set;}
+        public static string MasterUrl { get; set; }
 
         /// <summary>
         /// Log settings from configuration file
@@ -138,7 +139,9 @@ namespace WingServerCommon.Config
 
             //TODO load log settings
             var debugMode = ConfigurationManager.GetParammeter<BoolParameter>("Log", "Debug").Value;
-            LogSettings = new LogSettings(debugMode);
+            var traceLevelString = ConfigurationManager.GetParammeter<StringParameter>("Log", "Level").Value;
+            Enum.TryParse(traceLevelString, true, out TraceLevel traceLevel);
+            LogSettings = new LogSettings(debugMode, traceLevel);
             LoadRemedicalConfig();
             LoadStorageConfig();
             //TODO others      

+ 11 - 2
Config/LogSettings.cs

@@ -1,3 +1,4 @@
+using System.Diagnostics;
 namespace WingServerCommon.Config
 {
     public class LogSettings
@@ -6,10 +7,18 @@ namespace WingServerCommon.Config
         /// Indicates the logger is on debug mode
         /// </summary>
         /// <value></value>
-        public bool DebugMode {get;}
-        public LogSettings(bool debugMode)
+        public bool DebugMode { get; }
+
+        /// <summary>
+        /// Indicates the logger level
+        /// </summary>
+        /// <value></value>
+        public TraceLevel TraceLevel { get; }
+
+        public LogSettings(bool debugMode, TraceLevel traceLevel)
         {
             DebugMode = debugMode;
+            TraceLevel = traceLevel;
         }
     }
 }