Skip to content

Commit aa8344e

Browse files
Akka.Hosting.TestKit: added NullScope to xUnitLogger (#570)
This prevents a `NotImplementedException` from being thrown inside some test cases when working with other components that depend on scopes via Microsoft.Extensions.Logging
1 parent 0da91b8 commit aa8344e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Akka.Hosting.TestKit/Internals/XUnitLogger.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool IsEnabled(LogLevel logLevel)
7070

7171
public IDisposable BeginScope<TState>(TState state)
7272
{
73-
throw new NotImplementedException();
73+
return NullScope.Instance;
7474
}
7575

7676
private static bool TryFormatMessage<TState>(
@@ -91,6 +91,13 @@ private static bool TryFormatMessage<TState>(
9191
result = formattedMessage;
9292
return true;
9393
}
94+
95+
private class NullScope : IDisposable
96+
{
97+
private NullScope() { }
98+
public static NullScope Instance { get; } = new NullScope();
99+
public void Dispose() { }
100+
}
94101
}
95102
}
96103

0 commit comments

Comments
 (0)