Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 74bd1e40

Přidáno uživatelem Pultak před více než 2 roky(ů)

re #9439 logger code refactoring

Zobrazit rozdíly:

ld_client/LDClient/utils/ConfigLoader.cs
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;
1
using LDClient.utils.loggers;
7 2
using Microsoft.Extensions.Configuration;
8
using Microsoft.Extensions.Configuration.Json;
9 3

  
10
namespace LDClient {
11
    internal class ConfigurationLoader {
12

  
13
        private readonly string LOGGING_SECTION = "Logging";
4
namespace LDClient.utils {
5
    internal class ConfigLoader {
6
        private const string LoggingSection = "Logging";
14 7

  
15 8

  
16 9
        public int LogChunkSize { get; set; }
......
19 12

  
20 13
        public int LogCleanupPeriod { get; set; }
21 14

  
22
        private LogVerbosity _logVerbosity = LogVerbosity.Full;
23
        public LogVerbosity LogVerbosityType {
24
            get {
25
                return _logVerbosity;
26
            } 
27
            set 
28
                { _logVerbosity = value; 
29
            } 
30
        }
15
        public LogVerbosity LogVerbosityType { get; set; } = LogVerbosity.Full;
31 16

  
32
        private LogFlow _logFlowType = LogFlow.Console;
33
        public LogFlow LogFlowType { 
34
            get {
35
                return _logFlowType;
36
            } 
37
            set {
38
                _logFlowType = value;
39
            } 
40
        }
17
        public LogFlow LogFlowType { get; set; } = LogFlow.Console;
41 18

  
42
        public ConfigurationLoader() {
19
        public ConfigLoader() {
43 20
            var configuration = new ConfigurationBuilder()
44 21
                .AddJsonFile("appsettings.json")
45 22
                .Build();
46 23
            ReadAllSettings(configuration);
47 24
        }
48 25

  
49
        void ReadAllSettings(IConfigurationRoot configuration) {
26
        private void ReadAllSettings(IConfigurationRoot configuration) {
50 27

  
51 28
            try {
52
                var logging = configuration.GetSection(LOGGING_SECTION);
29
                var logging = configuration.GetSection(LoggingSection);
53 30
                //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"]);
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"]);
60 37

  
61 38

  
62 39
                Console.WriteLine("Configuration successfully loaded!");
63 40
            } catch (FormatException e) {
64 41
                //Console.WriteLine("Error reading app settings");
65 42
                //TODO: remove stacktrace print in production
66
                Console.WriteLine("Error during reading of configuration occured!" + e);
43
                Console.WriteLine("Error during reading of configuration occurred!" + e);
67 44
                throw new IOException("Reading of configuration file failed! " + e);
68 45
            }
69 46
        }

Také k dispozici: Unified diff