Repository navigation
Conversation
Serilog is plugged into the existing LogManager.Factory, so no logging call sites change. Logging is configured in serilog.json; an existing log4net.config is converted to it automatically at startup. log4net, Log4Net.Async and the log4net bridge are removed, along with the log4net audit suppressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mag-nus
force-pushed
the
serilog-switch
branch
from
November 25, 2026 13:57
055c348 to
f1957e3
Compare
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.
Switch logging from log4net to Serilog
Summary
ACE already logs through
Microsoft.Extensions.Loggingeverywhere (#4539, #4553), with a bridge passing every message on to log4net. This PR replaces log4net with Serilog:LogManager.FactorythroughSerilog.Extensions.Logging. No logging call sites change.serilog.jsoninstead oflog4net.config.log4net.configis converted toserilog.jsonautomatically at startup, so servers keep their logging setup without manual work.Because the messages are already message templates, Serilog keeps their values as structured properties. A sink that understands them (Seq, JSON files, and so on) can filter and search on a player name or GUID.
serilog.json
serilog.jsonuses Serilog's standard configuration format (Serilog.Settings.Configuration). It follows the same lifecyclelog4net.configdid:/ace/Configtakes precedence.log4net.configdoes (working directory, executable folder, or/ace/Configin a container), the log4net file is converted intoserilog.json.serilog.json.exampleis copied, orserilog.json.dockerin a container (also into/ace/Config, as before).If
serilog.jsoncan't be loaded (invalid JSON, or a setting Serilog rejects), the server still starts and logs Information and above to the console only. Its first log message is an error naming the file and the problem.serilog.jsonis git-ignored likelog4net.config. The build's pre-build step copies it between the project and output folders the same way.A relative log file path is relative to the executable's folder, as it was with log4net. Serilog on its own resolves relative paths against the working directory, which would move the logs of any server started from another folder, so
SerilogSetupresolves them before Serilog reads the config.The four shipped log4net examples are ported:
log4net.config.exampleserilog.json.examplelog4net.config.dockerserilog.json.dockerlog4net.config.ConsoleExampleserilog.json.ConsoleExamplelog4net.config.FilesExampleserilog.json.FilesExampleThe default config is the same as before: everything is logged,
Packetsat Information and above. The console shows Information and above, the fileACE_Log.txtshows everything and rolls at 20 MB keeping 10 old files. Writing is asynchronous. The two filtering examples use Serilog.Expressions filters in place of log4net's filter chains, and are now also asynchronous (see Performance).Changes take effect without a restart, for levels
log4net reloaded the whole file when it changed. Serilog reloads the minimum levels (the default and the per-logger overrides) when
serilog.jsonchanges, so turning on Debug for a logger still needs no restart. Changes to sinks, filters or output templates need a restart.Automatic log4net conversion
Logging/Log4NetConfigConverter.cstranslates a log4net XML config intoserilog.json:<root>level,<logger>levels (asMinimumLevel.Override), and the repositorythreshold.FileAppenderandRollingFileAppenderbecome the File sink, with file name, size limit, number of kept files, date-based rolling, shared locking and buffering.PatternLayoutpatterns become output templates, covering date (and its named formats), level, logger, thread, message, newline, exception and properties.SimpleLayoutis also supported.LevelMatchFilter,LevelRangeFilter,StringMatchFilter(text and regex),LoggerMatchFilterandDenyAllFilterbecome one Serilog.Expressions filter per sink. The filter keeps log4net's rules: filters run in order, the first one to accept or deny decides, and an event nothing decides is accepted.<logger>elements with their own appenders, includingadditivity="false"at any depth, are routed by logger name, following log4net's dot-separated hierarchy.%threadis kept exactly: the thread's name, or its id when it has no name ([World Manager],[1]). A small enricher in ACE.Server (WithThread) provides it.Anything that can't be converted exactly is skipped and logged as a warning when the server starts, for example an SMTP appender,
%methodin a pattern, or per-level console colours. The warning after a conversion also says thatlog4net.configis no longer read. The old file is left in place.If the conversion fails (for example malformed XML), the example config is used and an error says why.
Verified against log4net itself
Outside the repo, a harness ran each log4net config through log4net 2.0.17 with the old bridge, and the converted config through Serilog. Both received the same 210 messages (7 loggers, 5 levels, 6 message shapes), and the lines written to each output were compared.
acceptOnMatchsetting, nested forwarding and async appenders, logger levels, logger appenders andadditivity.LevelRangeFilteraccepts in-range events outright by default, and a non-additive logger also hides its events from loggers above it.All 820 distinct log templates in ACE (2,112 placeholders) were also parsed with both Microsoft's and Serilog's parser, and give the same placeholders.
Differences in output
INF,WRN,DBG,ERR,FTLinstead ofINFO,WARN, and so on.ACE_Log_001.txt,ACE_Log_002.txt, … with the newest file having the highest number. Previously the current file was alwaysACE_Log.txtand the backups wereACE_Log.txt.1,ACE_Log.txt.2, … Existing.1–.10backups are not touched or cleaned up.nulland[1,2]instead of(null)and1, 2.serilog.jsonloads, every report is printed, because a misspelled sink or enricher is skipped with nothing else to show for it. Once logging is running, a report is followed by a minute of silence: a failing sink reports every message it loses, so unthrottled this would be a console write per lost message.Performance
Measured with the old stack (log4net 2.0.17, Log4Net.Async, the bridge) and the new one side by side, Release build, .NET 10, 4 cores.
On the thread that logs (default config: everything on, one async queue):
{Message:l})Time is the same within about 10% either way. Allocation is 23–67% lower, because the message text is no longer built on the calling thread.
Console: Serilog's default console theme writes each part of a line separately with a colour change each time: 57 write calls per line against log4net's 5, and 7 times slower (142 µs against 19 µs per line). The shipped configs and the converter therefore set an ANSI theme, which writes each line once: 2 write calls and 12 µs per line. A plain
ConsoleAppenderconverts to the uncoloured theme, which is also a single write.Writing a file costs about 20% more per message than log4net (1.46 µs against 1.24 µs). In the default config that is on the background thread.
Filters on message text outside the async sink are the one case that is slower on the calling thread. Serilog builds the message text for each filter that checks it, where log4net received it already built. With five synchronous files and two regex filters (the old
FilesExampleshape), a message costs 2.6 µs and 2.6 KB against 1.8 µs and 0.5 KB. So:Async;Memory: the async queue holds up to 10,000 messages (Serilog's default) against Log4Net.Async's 1,000. At a few hundred bytes each that is under 10 MB at worst, and only while the writer is behind. Both drop messages when the queue is full. Values other than strings and numbers are turned into text when logged, so a queued message never keeps a game object alive.
Template cache: the provider caches up to 1,000 parsed templates. ACE has 820, none built at runtime and none over the 1,024-character cache limit.
Compatibility
log4net.config.ACE.Common.Logging.LogManager.Packages
Added to
ACE.Server:Serilog4.4.0Serilog.Extensions.Logging10.0.0Serilog.Settings.Configuration10.0.1Serilog.Sinks.Async2.1.0Serilog.Sinks.Console6.1.1Serilog.Sinks.File7.0.0Serilog.Expressions5.0.0Microsoft.Extensions.Configuration.Json10.0.15The versions stay on the .NET 10 line ACE already uses (Microsoft.Extensions.Logging 10.0.15).
Removed:
log4net2.0.17 andLog4Net.Async.Standard3.1.0.dotnet list package --vulnerable --include-transitivereports no vulnerable packages in any project.Testing
ACE.Server.Tests/Loggingpass:SourceContextand overrides apply to itserilog.json.exampleandserilog.json.dockerLevelRangeFilterdefault, console themes, date-pattern file extensions, unsupported appenders and rolling settings each have a testserilog.jsonwinslog4net.configfalls back to the exampleserilog.jsonapplies without a restartACE.Server.Tests(4),ACE.Database.Tests(7) andACE.DatLoader.Tests(6) fail the same tests as on master, all for environmental reasons.ACE.Adapter.Testspasses.log4net.config.exampleand noserilog.json. It converted the file, logged the conversion notice to the console and toACE_Log.txtnext to the executable, and wrote an unhandled-exception message to the file before exiting. A second start used the existingserilog.jsonunchanged.Files
Source/ACE.Server/Logging/SerilogSetup.cs(new): config file lifecycle, conversion, relative paths, SelfLog, provider setup and flushingSource/ACE.Server/Logging/Log4NetConfigConverter.cs(new)Source/ACE.Server/Logging/ThreadEnricher.cs(new)Source/ACE.Server/Logging/Log4NetBridgeProvider.cs(deleted)Source/ACE.Server/Program.cs: log4net startup replaced; flush on exit and on a terminating exceptionSource/ACE.Server/Entity/Actions/ActionQueue.cs: the last direct log4net logger, underWRAP_AND_MEASURE_ACT_WITH_STOPWATCHSource/ACE.Server/serilog.json.*(new),Source/ACE.Server/log4net.config.*(deleted)Source/ACE.Server/ACE.Server.csproj: packages, example files, pre-build copy step, audit suppression removedSource/ACE.Common/Logging/LogManager.cs: comments onlySource/ACE.Server.Tests/Logging/:SerilogProviderTests.cs,Log4NetConfigConverterTests.cs,SerilogSetupTests.csandTestData/(the old log4net configs);LogBridgeTests.csdeletedACE.Adapter,ACE.Database,ACE.DatLoaderand their test projects: log4net audit suppression removed.gitignore:serilog.json.github/dependabot.yml: log4net rule removed🤖 Generated with Claude Code