AppConfigSetting.cs
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using log4net;
using System;
using System.Configuration;
using System.Reflection;
using System.Threading;
using System.Xml;
namespace Common
{
public class AppConfigSetting
{
public static string GetStrVal(string key,string iniVal="")
{
return GetValue<string>(key, iniVal);
}
public static int GetIntVal(string key, int iniVal = 0)
{
return GetValue<int>(key, iniVal);
}
public static bool GetBoolVal(string key, bool iniVal = false)
{
return GetValue<bool>(key, iniVal);
}
static readonly LogBean log = new LogBean(MethodBase.GetCurrentMethod()?.DeclaringType.FullName);
static T GetValue<T>(string key, T defaultVal)
{
T val=defaultVal;
try
{
val= ConfigHelper.Config.Get(key, defaultVal);
}
catch(Exception ex)
{
LogUtil.Error($"获取配置{key}的值异常:", ex);
}
return val;
}
public static void SetStrVal(string key,string val)
{
SaveValue<string>(key, val);
}
static void SaveValue<T>(string key, T value)
{
try
{
ConfigHelper.Config.Set(key, value);
}
catch(Exception ex)
{
LogUtil.Error($"设置配置{key}的值为{value}异常:", ex);
}
}
}
}