public bool load() { try { if (!exists()) { if (this.dict == null) { Loging.LogError <JsonConfiguration>("加载配置失败,文件不存在:\n" + string.Join("\n", this.paths)); } else { Loging.LogError <JsonConfiguration>("加载配置失败,文件不存在:\n" + string.Join("\n", this.paths)); } return(false); } Dictionary <string, string> json = readJson(); if (json == null) { if (this.dict == null) { Loging.LogError <JsonConfiguration>("加载配置失败,文件格式不正确"); } else { Loging.LogError <JsonConfiguration>("加载配置失败,文件格式不正确"); } return(false); } this.dict = new Dictionary <string, string>(); foreach (string key in json.Keys) { this.dict[key.ToLower()] = json[key]; } } catch (Exception e) { if (this.dict == null) { Loging.LogError <JsonConfiguration>("加载配置失败", e); } else { Loging.LogWarning <JsonConfiguration>("加载配置失败", e); } return(false); } return(true); }
protected string _getValue(string key, string defaultValue) { string val = defaultValue; foreach (IConfiguration config in configList) { val = config.getValue(key); if (val != null) { break; } } if (val == null) { val = defaultValue; Loging.LogWarning <ConfigurationCenter>("未能读取配置信息:" + key); } return(val); }