From 32fc8d07670a8e3b809f2785483e664d32066a53 Mon Sep 17 00:00:00 2001 From: Chris Wolfgang <210299580+Chris-Wolfgang@users.noreply.github.com> Date: Sun, 26 Apr 2026 21:41:13 -0400 Subject: [PATCH] Fix Release-build analyzer errors Release builds now run 'dotnet build -c Release' with TreatWarningsAsErrors, which surfaced existing analyzer findings that Debug builds didn't enforce. src: - InMemoryLoggerBuilderExtensions.AddInMemoryLogger: add XML doc for ArgumentNullException (RCS1140) - InMemoryLoggerProvider.CreateLogger: add XML doc for ArgumentNullException (RCS1140) - InMemoryLoggerProvider: mark sealed (CA1063, S3881). The class has no overridable members and the existing no-op Dispose doesn't justify the full Dispose(bool) pattern. tests: - InMemoryLogger{,OfT}Tests.Log_when_called_adds_entry_to_LogEntries: - Name the 'exception' parameter explicitly (MA0003) - Discard unused 'exception' parameter in the formatter delegate (RCS1163, S3257) - Use indexer on IReadOnlyList instead of First() (CA1826) Verified locally: Release build 0/0, 52 tests pass on all TFMs. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../InMemoryLoggerBuilderExtensions.cs | 3 +++ .../InMemoryLoggerProvider.cs | 5 ++++- .../InMemoryLoggerOfTTests.cs | 6 +++--- .../InMemoryLoggerTests.cs | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerBuilderExtensions.cs b/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerBuilderExtensions.cs index 45fa458..84a757c 100644 --- a/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerBuilderExtensions.cs +++ b/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerBuilderExtensions.cs @@ -15,6 +15,9 @@ public static class InMemoryLoggerBuilderExtensions /// The to add the provider to. /// The instance to register. /// The so that additional calls can be chained. + /// + /// Thrown when or is . + /// /// /// /// var provider = new InMemoryLoggerProvider(); diff --git a/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerProvider.cs b/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerProvider.cs index ce52f70..abc25e3 100644 --- a/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerProvider.cs +++ b/src/Wolfgang.Extensions.Logging.InMemoryLogger/InMemoryLoggerProvider.cs @@ -11,7 +11,7 @@ namespace Wolfgang.Extensions.Logging.InMemoryLogger; /// An that creates instances /// and provides access to all log entries across all loggers. /// -public class InMemoryLoggerProvider : ILoggerProvider +public sealed class InMemoryLoggerProvider : ILoggerProvider { private readonly ConcurrentDictionary _loggers = new ConcurrentDictionary(StringComparer.Ordinal); @@ -36,6 +36,9 @@ public InMemoryLoggerProvider(LogLevel minLogLevel = LogLevel.Trace) /// /// The category name for messages produced by the logger. /// An instance. + /// + /// Thrown when is . + /// public ILogger CreateLogger(string categoryName) { if (categoryName == null) diff --git a/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerOfTTests.cs b/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerOfTTests.cs index 76cf50c..9d1e968 100644 --- a/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerOfTTests.cs +++ b/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerOfTTests.cs @@ -30,12 +30,12 @@ public void Log_when_called_adds_entry_to_LogEntries() LogLevel.Information, new EventId(1, "TestEvent"), "Test message", - null, - (state, exception) => state + exception: null, + (state, _) => state ); Assert.Single(sut.LogEntries); - var logEntry = sut.LogEntries.First(); + var logEntry = sut.LogEntries[0]; Assert.Equal(LogLevel.Information, logEntry.LogLevel); Assert.Equal(1, logEntry.EventId.Id); Assert.Equal("TestEvent", logEntry.EventId.Name); diff --git a/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerTests.cs b/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerTests.cs index b3efea2..e1e0f72 100644 --- a/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerTests.cs +++ b/tests/Wolfgang.Extensions.Logging.InMemoryLogger.Tests.Unit/InMemoryLoggerTests.cs @@ -78,12 +78,12 @@ public void Log_when_called_adds_entry_to_LogEntries() LogLevel.Information, new EventId(1, "TestEvent"), "Test message", - null, - (state, exception) => state + exception: null, + (state, _) => state ); Assert.Single(sut.LogEntries); - var logEntry = sut.LogEntries.First(); + var logEntry = sut.LogEntries[0]; Assert.Equal(LogLevel.Information, logEntry.LogLevel); Assert.Equal("TestCategory", logEntry.Category); Assert.Equal(1, logEntry.EventId.Id);