| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HXX.Scanner.Common
- {
- /// <summary>
- /// 配置文件app.config操作类
- /// </summary>
- public class ConfigManager
- {
- /// <summary>
- /// 获取配置信息
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public static string GetConfig(string key)
- {
- var result = string.Empty;
- try
- {
- var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- result = config.AppSettings.Settings[key].Value;
- }
- catch (Exception ee)
- {
- LogManager.WriteLog(ee.Message);
- }
- return result;
- }
- /// <summary>
- /// 设置配置信息
- /// </summary>
- /// <param name="key"></param>
- /// <param name="value"></param>
- public static void SetConfig(string key, string value)
- {
- try
- {
- var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- config.AppSettings.Settings[key].Value = value;
- config.Save();
- }
- catch (Exception ee)
- {
- LogManager.WriteLog(ee.Message);
- }
- }
- }
- }
|