Browse Source

Removing logging in ConfigurationCache

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
9b70d09447
1 tập tin đã thay đổi với 16 bổ sung7 xóa
  1. 16 7
      InABox.Core/Configuration/ConfigurationCache.cs

+ 16 - 7
InABox.Core/Configuration/ConfigurationCache.cs

@@ -17,6 +17,8 @@ namespace InABox.Configuration
         private static readonly Dictionary<Type, Dictionary<string, string>> _globalcache = new Dictionary<Type, Dictionary<string, string>>();
         private static readonly Dictionary<Type, Dictionary<string, string>> _usercache = new Dictionary<Type, Dictionary<string, string>>();
 
+        private static readonly bool _shouldLog = false;
+
         private static Dictionary<Type, Dictionary<string, string>> GetCache(ConfigurationCacheType type)
         {
             return type == ConfigurationCacheType.Local
@@ -26,9 +28,17 @@ namespace InABox.Configuration
                     : _usercache;
         }
 
+        private static void Log(LogType type, string message)
+        {
+            if (_shouldLog)
+            {
+                Logger.Send(type, "", message);
+            }
+        }
+
         public static T Check<T>(ConfigurationCacheType type, string section)
         {
-            Logger.Send(LogType.Information, "", string.Format("- Checking {0}({1},{2})", typeof(T), type, section));
+            Log(LogType.Information, $"- Checking {typeof(T)}({type},{section})");
             var _cache = GetCache(type);
             if (_cache.ContainsKey(typeof(T)))
             {
@@ -38,20 +48,19 @@ namespace InABox.Configuration
                     var data = subcache[section];
                     if (!string.IsNullOrWhiteSpace(data))
                     {
-                        Logger.Send(LogType.Information, "",
-                            string.Format("- Checking: Found {0}({1},{2}) -> {3}", typeof(T), type, section, subcache[section]));
+                        Log(LogType.Information, $"- Checking: Found {typeof(T)}({type},{section}) -> {subcache[section]}");
                         var result = Serialization.Deserialize<T>(subcache[section]);
                         return result;
                     }
                 }
             }
 
-            return default(T);
+            return default;
         }
 
         public static void Add<T>(ConfigurationCacheType type, string section, T config)
         {
-            Logger.Send(LogType.Information, "", string.Format("- Adding {0}({1},{2})", typeof(T), type, section));
+            Log(LogType.Information, $"- Adding {typeof(T)}({type},{section})");
             var _cache = GetCache(type);
             if (!_cache.ContainsKey(typeof(T)))
                 _cache[typeof(T)] = new Dictionary<string, string>();
@@ -61,14 +70,14 @@ namespace InABox.Configuration
 
         public static void Clear<T>(ConfigurationCacheType type, string section)
         {
-            Logger.Send(LogType.Information, "", string.Format("- Clearing {0}({1},{2})", typeof(T), type, section));
+            Log(LogType.Information, $"- Clearing {typeof(T)}({type},{section})");
             var _cache = GetCache(type);
             if (_cache.ContainsKey(typeof(T)))
             {
                 var subcache = _cache[typeof(T)];
                 if (subcache.ContainsKey(section))
                 {
-                    Logger.Send(LogType.Information, "", string.Format("- Clearing: Removing {0}({1},{2})", typeof(T), type, section));
+                    Log(LogType.Information, $"- Clearing: Removing {typeof(T)}({type},{section})");
                     subcache[section] = "";
                 }
             }