-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServiceLogManager.cs
79 lines (71 loc) · 2.13 KB
/
ServiceLogManager.cs
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
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomWatchdog
{
class ServiceLogManager : IServiceLog
{
private readonly List<IServiceLog> m_logs = new List<IServiceLog>();
public ServiceLogLevel Level { get; set; }
public void Add(IServiceLog log)
{
m_logs.Add(log);
var l = log.Level;
if (l < Level)
{
Level = l;
}
}
public void Write(ServiceLogLevel level, string msg)
{
foreach (var log in m_logs)
{
if (log.Level <= level)
{
log.Write(level, msg);
}
}
}
internal static IEnumerable<IServiceLog> Create(IList<RecoveryConfigLog> logDefs)
{
if (logDefs != null && logDefs.Count > 0)
{
var logs = new List<IServiceLog>(logDefs.Count);
foreach (var logDef in logDefs)
{
switch (logDef.Enums.LogType)
{
case ServiceLogType.File:
logs.Add(ServiceLogFile.Create(logDef));
break;
case ServiceLogType.Debug:
logs.Add(ServiceLogDebug.Create(logDef));
break;
case ServiceLogType.Event:
logs.Add(ServiceLogEvent.Create(logDef));
break;
default:
throw new NotImplementedException(logDef.ToString());
}
}
return logs;
}
return Enumerable.Empty<IServiceLog>();
}
public void Dispose()
{
foreach (var item in m_logs)
{
try
{
item.Dispose();
}
catch
{
}
}
}
}
}