1
|
using LDClient.utils.loggers;
|
2
|
using Microsoft.Extensions.Configuration;
|
3
|
|
4
|
namespace LDClient.utils {
|
5
|
internal class ConfigLoader {
|
6
|
private const string LoggingSection = "Logging";
|
7
|
|
8
|
|
9
|
public int LogChunkSize { get; set; }
|
10
|
public int LogChunkMaxCount { get; set; }
|
11
|
public int LogArchiveMaxCount { get; set; }
|
12
|
|
13
|
public int LogCleanupPeriod { get; set; }
|
14
|
|
15
|
public LogVerbosity LogVerbosityType { get; set; } = LogVerbosity.Full;
|
16
|
|
17
|
public LogFlow LogFlowType { get; set; } = LogFlow.Console;
|
18
|
|
19
|
public ConfigLoader() {
|
20
|
var configuration = new ConfigurationBuilder()
|
21
|
.AddJsonFile("appsettings.json")
|
22
|
.Build();
|
23
|
ReadAllSettings(configuration);
|
24
|
}
|
25
|
|
26
|
private void ReadAllSettings(IConfigurationRoot configuration) {
|
27
|
|
28
|
try {
|
29
|
var logging = configuration.GetSection(LoggingSection);
|
30
|
//TODO: Exception handling
|
31
|
LogChunkSize = int.Parse(logging["LogChunkSize"]);
|
32
|
LogChunkMaxCount = int.Parse(logging["LogChunkMaxCount"]);
|
33
|
LogArchiveMaxCount = int.Parse(logging["LogArchiveMaxCount"]);
|
34
|
LogCleanupPeriod = int.Parse(logging["LogCleanupPeriod"]);
|
35
|
LogFlowType = (LogFlow)int.Parse(logging["LogFlowType"]);
|
36
|
LogVerbosityType = (LogVerbosity)int.Parse(logging["LogVerbosityType"]);
|
37
|
|
38
|
|
39
|
Console.WriteLine("Configuration successfully loaded!");
|
40
|
} catch (FormatException e) {
|
41
|
//Console.WriteLine("Error reading app settings");
|
42
|
//TODO: remove stacktrace print in production
|
43
|
Console.WriteLine("Error during reading of configuration occurred!" + e);
|
44
|
throw new IOException("Reading of configuration file failed! " + e);
|
45
|
}
|
46
|
}
|
47
|
|
48
|
}
|
49
|
}
|