-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigUtility.cs
38 lines (31 loc) · 1.15 KB
/
ConfigUtility.cs
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
namespace WindowsServiceAIFailure
{
using System.Configuration;
using System.Reflection;
public static class ConfigUtility
{
private const string InstrumentationKey = "Azure.ApplicationInsights.InstrumentationKey";
private static readonly Configuration configFile;
private static readonly KeyValueConfigurationCollection settings;
static ConfigUtility()
{
var assembly = Assembly.GetAssembly(typeof(TestService));
assembly = assembly ?? Assembly.GetEntryAssembly();
configFile = ConfigurationManager.OpenExeConfiguration(assembly?.Location);
settings = configFile.AppSettings.Settings;
}
public static void WriteKeyValue(string value)
{
if (settings[InstrumentationKey] == null)
{
settings.Add(InstrumentationKey, value);
}
else
{
settings[InstrumentationKey].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
}
public static string GetKeyValue() => settings[InstrumentationKey].Value;
}
}