-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
TestLogger.cs
62 lines (51 loc) · 1.38 KB
/
TestLogger.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
using Microsoft.Extensions.Logging;
using System;
using System.Text;
namespace YesSql.Tests
{
public class TestLogger : ILogger
{
private object _lockObj = new object();
private readonly StringBuilder _builder;
public TestLogger(StringBuilder builder = null)
{
_builder = builder ?? new StringBuilder();
}
public IDisposable BeginScope<TState>(TState state)
{
return new FakeScope();
}
public bool IsEnabled(LogLevel logLevel)
{
return IsLevelEnabled(logLevel);
}
public bool IsLevelEnabled(LogLevel logLevel)
{
return true;
}
public void Log(LogLevel logLevel, string log)
{
lock (_lockObj)
{
_builder.AppendLine(logLevel.ToString().ToUpper() + ": " + log);
}
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Log(logLevel, formatter(state, exception));
}
public override string ToString()
{
lock (_lockObj)
{
return _builder.ToString();
}
}
}
public class FakeScope : IDisposable
{
public void Dispose()
{
}
}
}