-
Notifications
You must be signed in to change notification settings - Fork 3
/
NamedLogger.cs
44 lines (27 loc) · 1003 Bytes
/
NamedLogger.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
using Gsemac.IO.Logging.Properties;
using System;
namespace Gsemac.IO.Logging {
public class NamedLogger :
ILogger {
// Public members
public event LogEventHandler MessageLogged;
public bool Enabled { get; set; } = true;
public string Name { get; }
public ILogRetentionPolicy RetentionPolicy {
get => baseLogger.RetentionPolicy;
set => throw new NotSupportedException(string.Format(ExceptionMessages.ClassDoesNotSupportRetentionPolicies, nameof(NamedLogger)));
}
public NamedLogger(ILogger baseLogger, string name) {
this.baseLogger = baseLogger;
this.Name = name;
}
public void Log(ILogMessage message) {
if (!Enabled)
return;
baseLogger.Log(message);
MessageLogged?.Invoke(this, new LogEventArgs(message));
}
// Private members
private readonly ILogger baseLogger;
}
}