refactor: migrate Serilog.ILogger to Microsoft.Extensions.Logging.ILogger<T>#2090
Merged
erwan-joly merged 1 commit intomasterfrom Apr 24, 2026
Merged
refactor: migrate Serilog.ILogger to Microsoft.Extensions.Logging.ILogger<T>#2090erwan-joly merged 1 commit intomasterfrom
erwan-joly merged 1 commit intomasterfrom
Conversation
…g.ILogger<T> Replaces non-generic Serilog.ILogger injection with Microsoft.Extensions.Logging.ILogger<T> across NosCore. Closes #1607. - Fields/ctor params: `ILogger` -> `ILogger<ContainingClass>` everywhere the logger is owned by a specific type. - Method calls: `.Information/.Warning/.Error/.Debug/.Verbose/.Fatal` -> `.LogInformation/.LogWarning/.LogError/.LogDebug/.LogTrace/.LogCritical`. - Abstract bases (`BaseHubClient`, `NetworkClient`) keep non-generic `ILogger` so derived classes can pass their own `ILogger<Derived>` through the inheritance chain (MEL `ILogger<T>` extends `ILogger`). - Classes that construct typed-logger inner classes (`ItemGenerationService`, `MapInstanceGeneratorService`, parsers, `ImportFactory`) now take `ILoggerFactory` and call `CreateLogger<Inner>()` at instantiation. - Autofac `As<Serilog.ILogger>()` bindings removed; ILogger<T> auto-wires via `services.AddLogging()` through AutofacServiceProviderFactory. Serilog stays as the backend provider via `UseSerilog()`. - `Directory.Packages.props`: bump NosCore.Dao 4.0.5 -> 5.0.0 and NosCore.Networking 7.1.0 -> 8.0.0 (both packages migrated in separate PRs, tagged, and published to nuget.org). - Test mocks rewired per target class: `Mock<ILogger<TargetType>>` at each instantiation site; test helpers use `NullLogger<T>.Instance` / `NullLoggerFactory.Instance` where verification isn't needed. - Moq `.Verify(l => l.LogXxx(...))` on extension methods rewritten to match the underlying `Log(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)` interface method. Closes #1607. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedToo many files! This PR contains 196 files, which is 46 over the limit of 150. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (196)
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces non-generic
Serilog.ILoggerinjection withMicrosoft.Extensions.Logging.ILogger<T>across NosCore. Closes #1607.What changed
ILogger→ILogger<ContainingClass>on fields, ctor params and primary-ctor params wherever a logger is owned by a specific type..Information/.Warning/.Error/.Debug/.Verbose/.Fatal→.LogInformation/.LogWarning/.LogError/.LogDebug/.LogTrace/.LogCritical.BaseHubClient,NetworkClient) keep non-genericILoggerso derived classes pass their ownILogger<Derived>through inheritance (MELILogger<T>extendsILogger).newinner classes requiring typed loggers (ItemGenerationService→WearableInstance,MapInstanceGeneratorService→MapInstance, the parsers →GenericParser<T>/FluentParser<T>/I18NParser<T,PK>,ImportFactory→ 10×I18NParser<…>) now injectILoggerFactoryand callCreateLogger<Inner>()at the construction site.Register(_ => Log.Logger).As<Serilog.ILogger>().SingleInstance()bindings.ILogger<T>auto-wires through Microsoft DI into Autofac viaAutofacServiceProviderFactory. Serilog stays as the backend provider viaUseSerilog()— no log output changes.PersistenceModuleresolve a string-categorized logger viaILoggerFactory.CreateLogger(nameof(…))becauseMasterServerBootstrapisstaticand can't be a type arg.Dependencies (already published)
NosCore.Dao5.0.0 — breaking:Dao<TEntity, TDto, TPk>now takesILogger<Dao<TEntity, TDto, TPk>>.NosCore.Networking8.0.0 — breaking:NetworkClientnow takesMicrosoft.Extensions.Logging.ILogger.Directory.Packages.propsbumped to consume both.Testing
dotnet build— green (0 errors, 0 warnings).dotnet test— 924/924 passing across all suites (Core, Database, Parser, WebApi, GameObject, PacketHandlers).Moq
.Verifycalls targeting extension methods (LogError,LogWarningetc.) were rewritten to verify the underlyingLog(LogLevel, EventId, TState, Exception?, Func<TState, Exception?, string>)interface method, since extension methods can't be intercepted by Moq.Test plan
ILogger<T>via MEL→Serilog).Generated with Claude Code