-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathTestContextAppender.cs
More file actions
29 lines (25 loc) · 913 Bytes
/
TestContextAppender.cs
File metadata and controls
29 lines (25 loc) · 913 Bytes
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
namespace ServiceControl.Infrastructure.TestLogger
{
using System;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
class TestContextAppender(string categoryName, LogLevel level) : ILogger
{
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (IsEnabled(logLevel))
{
TestContext.Out.WriteLine($"{categoryName}: {formatter(state, exception)}");
}
}
public bool IsEnabled(LogLevel logLevel) => logLevel >= level;
public IDisposable BeginScope<TState>(TState state) where TState : notnull => Disposable.Instance;
class Disposable : IDisposable
{
public static Disposable Instance = new();
public void Dispose()
{
}
}
}
}