1
|
using System;
|
2
|
using System.Collections.Generic;
|
3
|
using System.Configuration;
|
4
|
using System.Linq;
|
5
|
using System.Text;
|
6
|
using System.Threading.Tasks;
|
7
|
using Microsoft.Extensions.Configuration;
|
8
|
using Microsoft.Extensions.Configuration.Json;
|
9
|
|
10
|
namespace LDClient {
|
11
|
internal class ConfigurationLoader {
|
12
|
|
13
|
private readonly string LOGGING_SECTION = "Logging";
|
14
|
|
15
|
|
16
|
public int LogChunkSize { get; set; }
|
17
|
public int LogChunkMaxCount { get; set; }
|
18
|
public int LogArchiveMaxCount { get; set; }
|
19
|
|
20
|
public int LogCleanupPeriod { get; set; }
|
21
|
|
22
|
private LogVerbosity _logVerbosity = LogVerbosity.Full;
|
23
|
public LogVerbosity LogVerbosityType {
|
24
|
get {
|
25
|
return _logVerbosity;
|
26
|
}
|
27
|
set
|
28
|
{ _logVerbosity = value;
|
29
|
}
|
30
|
}
|
31
|
|
32
|
private LogFlow _logFlowType = LogFlow.Console;
|
33
|
public LogFlow LogFlowType {
|
34
|
get {
|
35
|
return _logFlowType;
|
36
|
}
|
37
|
set {
|
38
|
_logFlowType = value;
|
39
|
}
|
40
|
}
|
41
|
|
42
|
public ConfigurationLoader() {
|
43
|
var configuration = new ConfigurationBuilder()
|
44
|
.AddJsonFile("appsettings.json")
|
45
|
.Build();
|
46
|
ReadAllSettings(configuration);
|
47
|
}
|
48
|
|
49
|
void ReadAllSettings(IConfigurationRoot configuration) {
|
50
|
|
51
|
try {
|
52
|
var logging = configuration.GetSection(LOGGING_SECTION);
|
53
|
//TODO: Exception handling
|
54
|
LogChunkSize = Int32.Parse(logging["LogChunkSize"]);
|
55
|
LogChunkMaxCount = Int32.Parse(logging["LogChunkMaxCount"]);
|
56
|
LogArchiveMaxCount = Int32.Parse(logging["LogArchiveMaxCount"]);
|
57
|
LogCleanupPeriod = Int32.Parse(logging["LogCleanupPeriod"]);
|
58
|
LogFlowType = (LogFlow)Int32.Parse(logging["LogFlowType"]);
|
59
|
LogVerbosityType = (LogVerbosity)Int32.Parse(logging["LogVerbosityType"]);
|
60
|
|
61
|
|
62
|
Console.WriteLine("Configuration successfully loaded!");
|
63
|
} catch (FormatException e) {
|
64
|
//Console.WriteLine("Error reading app settings");
|
65
|
//TODO: remove stacktrace print in production
|
66
|
Console.WriteLine("Error during reading of configuration occured!" + e);
|
67
|
throw new IOException("Reading of configuration file failed! " + e);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
}
|
72
|
}
|