Skip to content

Commit c266fe3

Browse files
Fix BeginScope to return proper disposable and AddProvider to throw NotSupportedException
Co-authored-by: MichaelKoster70 <[email protected]>
1 parent 79e424e commit c266fe3

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/Extension/RemoteDebuggerLauncher/Logging/FileLogger.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public FileLogger(string categoryName, string logFilePath, LogLevel minLogLevel)
3939
/// <inheritdoc />
4040
public IDisposable BeginScope<TState>(TState state)
4141
{
42-
return null;
42+
return NullScope.Instance;
4343
}
4444

4545
/// <inheritdoc />
@@ -130,5 +130,22 @@ private static string GetLogLevelString(LogLevel logLevel)
130130
return "UNKN ";
131131
}
132132
}
133+
134+
/// <summary>
135+
/// A no-op disposable for scope handling.
136+
/// </summary>
137+
private sealed class NullScope : IDisposable
138+
{
139+
public static NullScope Instance { get; } = new NullScope();
140+
141+
private NullScope()
142+
{
143+
}
144+
145+
public void Dispose()
146+
{
147+
// Do nothing
148+
}
149+
}
133150
}
134151
}

src/Extension/RemoteDebuggerLauncher/Logging/FileLoggerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public ILogger CreateLogger(string categoryName)
5050
}
5151

5252
/// <inheritdoc />
53+
/// <remarks>This simple implementation does not support adding providers.</remarks>
5354
public void AddProvider(ILoggerProvider provider)
5455
{
55-
// Not supported for this simple implementation
56+
throw new NotSupportedException("This logger factory does not support adding providers.");
5657
}
5758

5859
/// <inheritdoc />

src/Extension/RemoteDebuggerLauncher/Logging/NullLogger.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class NullLogger : ILogger
2323
/// <inheritdoc />
2424
public IDisposable BeginScope<TState>(TState state)
2525
{
26-
return null;
26+
return NullScope.Instance;
2727
}
2828

2929
/// <inheritdoc />
@@ -37,5 +37,22 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3737
{
3838
// Do nothing
3939
}
40+
41+
/// <summary>
42+
/// A no-op disposable for scope handling.
43+
/// </summary>
44+
private sealed class NullScope : IDisposable
45+
{
46+
public static NullScope Instance { get; } = new NullScope();
47+
48+
private NullScope()
49+
{
50+
}
51+
52+
public void Dispose()
53+
{
54+
// Do nothing
55+
}
56+
}
4057
}
4158
}

0 commit comments

Comments
 (0)