Repository navigation
Use standard ILogger calls everywhere - #4553
Merged
Merged
Conversation
Convert all log4net-style LogExtensions calls (Info, WarnFormat, IsDebugEnabled, ...) to the standard Microsoft.Extensions.Logging API with named message templates, and delete LogExtensions.cs. Also fixes HouseManager.HandleRentPaid always logging "0" instead of the player name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LtRipley36706
approved these changes
Nov 24, 2026
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.
Use standard ILogger calls everywhere
The problem
Logging already runs on
Microsoft.Extensions.Logging.ILogger, but every call site still used log4net-style extension methods fromACE.Common/Logging/LogExtensions.cs:Info,Warn,DebugFormat,IsDebugEnabledand so on. They were added so the move from log4net'sILogtoILoggercould land without touching every call.That leaves ACE on its own logging API, and every message reaches the logger as one pre-built string. As a result:
log.Debug($"...")builds its string before the call, unless the call is wrapped in anIsDebugEnabledcheck. The*Formatcalls also allocate their argument array before the level check runs.The fix
Every call now uses the standard API, and
LogExtensions.csis deleted.log.Debug/DebugFormatlog.LogDebuglog.Info/InfoFormatlog.LogInformationlog.Warn/WarnFormatlog.LogWarninglog.Error/ErrorFormatlog.LogErrorlog.Fatal/FatalFormatlog.LogCriticallog.IsDebugEnabled(and the other levels)log.IsEnabled(LogLevel.Debug)Messages become message templates with named values:
Totals: 951 calls and 62 level checks, across 155 files.
How it was converted
A Roslyn syntax rewriter did the conversion, not regex:
"text" + valuechains become templates. Each interpolation hole becomes a named value, and its format and alignment are kept, for example{TargetGuid:X8}.*Formatcalls have their{0}-style placeholders replaced with names taken from the matching argument.targetGuid→TargetGuid,player.Name→Name,item.Guid.Full→Guid,GetFullMessage()→FullMessage. When two different values in one message would get the same name, they are qualified with their owner:PlayerNameandTargetName. About 40 values with no natural name were named by hand. These are mostly conditional text fragments such as(playerCount > 1 ? "s" : ""), which became{PlayerPlural}.x.ToString("fmt")becomes{X:fmt}, which renders the same text but keeps the value structured.StringBuilder,Environment.StackTrace) go in as"{Message:l}". That is the same formLogExtensionsused internally, so their output is unchanged.log.Error(ex), where the exception was the whole message, becomeslog.LogError(ex, "{Message:l}", ex.Message). As before, the exception is attached and its message is the text.#if DEBUGand#if WRAP_AND_MEASURE_ACT_WITH_STOPWATCHblocks were converted too, by re-parsing with those symbols defined.using Microsoft.Extensions.Logging;is added in the third-party group where a file didn't already have it.using ACE.Common.Logging;is removed from files that no longer useLogManager.Commented-out log calls (about 80) are left as they were.
One existing bug fixed
HouseManager.HandleRentPaidmixed$"..."withInfoFormat's{0}. The interpolation turned{0}into a literal0beforeInfoFormatever saw it, so the log line has always readHandleRentPaid(0)instead of the player's name. It now logs the name.Differences in log output
Most messages render exactly as before. The differences come from how
ILoggerformats values compared with C# interpolation:(null)instead of an empty string.ToCommonString().Compatibility
LogExtensionswas public inACE.Common. A mod that callslog.Info(...)or the other log4net-style methods on anILoggerwill no longer compile against this build. Such mods need the same one-line change toLogInformationand the rest.Testing
ACE.Server.Tests/Logging/LogBridgeTests.csis rewritten for the standard API, and all 7 tests pass. Through the log4net bridge they check:IsEnabledfollows the configured levelACE.Server.Tests(4),ACE.Database.Tests(7) andACE.DatLoader.Tests(6) fail the same tests as on master, all for environmental reasons: no config file, database or retail dat files.Files
Source/(call sites)Source/ACE.Common/Logging/LogExtensions.cs(deleted)Source/ACE.Server.Tests/Logging/LogBridgeTests.cs🤖 Generated with Claude Code