-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileLoggerConfiguration.cs
More file actions
77 lines (68 loc) · 2.1 KB
/
FileLoggerConfiguration.cs
File metadata and controls
77 lines (68 loc) · 2.1 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using System;
namespace Youzee.Util.Logger
{
/**
* Logger configuration based on a configuration file
*
* @copyright (C) Youzee (2012)
* @author Keyvan Akbary <keyvan@youzee.com>
* @version 1.0
*/
public class FileLoggerConfiguration : LoggerConfiguration
{
private const string LOGGER_SECTION_NAME = "logger";
private Dictionary<string, ArrayList> LogLevelFiles;
/**
* Constructor
*/
public FileLoggerConfiguration()
{
LogLevelFiles = new Dictionary<string, ArrayList>();
ExtractLogConfiguration();
}
private void ExtractLogConfiguration()
{
try
{
LogCollection logCollection = GetLogCollectionFromConfiguration();
foreach (LogElement log in logCollection)
{
LoadLogElementIntoLogLevelFiles(log);
}
}
catch (NullReferenceException e)
{
throw new ConfigurationException();
}
}
private void LoadLogElementIntoLogLevelFiles(LogElement log)
{
ArrayList logs;
if (!LogLevelFiles.TryGetValue(log.Level, out logs))
{
logs = new ArrayList();
LogLevelFiles.Add(log.Level, logs);
}
logs.Add(log);
}
private LogCollection GetLogCollectionFromConfiguration()
{
LoggerSection loggerSection = (LoggerSection)System.Configuration.ConfigurationManager.GetSection(LOGGER_SECTION_NAME);
return loggerSection.Logger;
}
/**
* @see LoggerConfiguration
*/
public ArrayList GetLogElementsForLevel(string level)
{
ArrayList logElements;
if (!LogLevelFiles.TryGetValue(level, out logElements))
{
throw new LogLevelConfigurationNotFoundException(level);
}
return logElements;
}
}
}