This repository has been archived by the owner on May 29, 2021. It is now read-only.
/
ConsoleLogger.cs
53 lines (46 loc) · 1.64 KB
/
ConsoleLogger.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
using System;
using Microsoft.Extensions.Logging;
namespace FlickrFollowerBot
{
internal class ConsoleLogger : ILogger
{
private static void Log(ConsoleColor color, string message, ConsoleColor debugColor, object debug)
{
Console.ForegroundColor = color;
Console.WriteLine(message);
if (debug != null)
{
Console.ForegroundColor = debugColor;
Console.WriteLine(debug);
}
Console.ResetColor();
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
switch (logLevel)
{
case LogLevel.Critical:
case LogLevel.Error:
Log(ConsoleColor.Red, formatter(state, exception), ConsoleColor.DarkRed, exception);
break;
case LogLevel.Warning:
Log(ConsoleColor.Yellow, formatter(state, exception), ConsoleColor.DarkYellow, exception);
break;
case LogLevel.Information:
Log(ConsoleColor.White, formatter(state, exception), 0, exception);
break;
default:
Log(ConsoleColor.DarkGray, formatter(state, exception), 0, exception);
break;
}
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
}
}
}