-
-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathDefaultLogger.cs
More file actions
52 lines (43 loc) · 1.64 KB
/
DefaultLogger.cs
File metadata and controls
52 lines (43 loc) · 1.64 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
using Microsoft.Extensions.Logging;
using System;
namespace Discord.Logging
{
internal class DefaultLogger : ILogger
{
private static readonly object _lock = new object();
private LogLevel MinimumLevel { get; }
internal DefaultLogger(LogLevel minLevel = LogLevel.Information)
{
this.MinimumLevel = minLevel;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (!this.IsEnabled(logLevel))
return;
lock (_lock)
{
Console.Write($"{DateTime.Now} ");
Console.Write(logLevel switch
{
LogLevel.Trace => "[Trace] ",
LogLevel.Debug => "[Debug] ",
LogLevel.Information => "[Info ] ",
LogLevel.Warning => "[Warn ] ",
LogLevel.Error => "[Error] ",
LogLevel.Critical => "[Crit ] ",
LogLevel.None => "[None ] ",
_ => "[?????] "
});
var message = formatter(state, exception);
Console.WriteLine(message);
if (exception != null)
Console.WriteLine(exception);
}
}
public bool IsEnabled(LogLevel logLevel) => logLevel >= this.MinimumLevel;
public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
}
}
}