-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathConfigUtils.cs
More file actions
45 lines (40 loc) · 1.38 KB
/
Copy pathConfigUtils.cs
File metadata and controls
45 lines (40 loc) · 1.38 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
// Copyright (c) One Identity LLC. All rights reserved.
namespace ServiceNowTicketValidator
{
using System;
using System.Configuration;
using Serilog;
internal static class ConfigUtils
{
public static string ReadRequiredSettingFromAppConfig(string key, string description)
{
try
{
var value = ConfigurationManager.AppSettings[key];
if (!string.IsNullOrEmpty(value))
{
return value;
}
Log.Error("{Key} is required in App.Config", key);
throw new InvalidOperationException($"Unable to start ServiceNowTicketValidator with empty {description}.");
}
catch (ConfigurationErrorsException ex)
{
Log.Error(ex, "{Key} is required in App.Config", key);
throw new InvalidOperationException($"Unable to start ServiceNowTicketValidator without {description}.", ex);
}
}
public static string ReadSettingFromAppConfigIfPresent(string key)
{
try
{
var value = ConfigurationManager.AppSettings[key];
return !string.IsNullOrEmpty(value) ? value : null;
}
catch (ConfigurationErrorsException)
{
return null;
}
}
}
}