Skip to content

Use Serilog throughout GameServer#64

Open
SzymonKaminski wants to merge 3 commits intothemeldingwars:masterfrom
SzymonKaminski:serilog
Open

Use Serilog throughout GameServer#64
SzymonKaminski wants to merge 3 commits intothemeldingwars:masterfrom
SzymonKaminski:serilog

Conversation

@SzymonKaminski
Copy link
Contributor

I've modified logging configuration of GameServer.
By default logs are still shown in console, but they can be sent to Seq and/or saved to files in logs/ directory.
It's also possible to filter logs by game systems and change global log level after startup (using Seq).
System names are extracted from namespaces: Aptitude, Entities, Network, Data, Physics, etc.

New App.config file settings:

  • serilog:write-to accepts comma delimited values: Console, Seq, File, None
  • serilog:system-level:<SystemName> controls min level of logs within Network or any other system

As a reminder, built-in settings:

  • serilog:minimum-level controls global min level of logs
  • serilog:minimum-level:override:GameServer.Entities controls min level of logs within GameServer.Entities SourceContext

General rule applies - the logging level can only be raised for sinks or systems, not lowered.
If the logger's MinimumLevel is set to Information then a sink with Debug as its specified level will still only see Information level events.

Min log level per sink can be configured using these built-in settings:

  • serilog:write-to:Console.restrictedToMinimumLevel
  • serilog:write-to:File.restrictedToMinimumLevel
  • serilog:write-to:Seq.restrictedToMinimumLevel

The settings use default key names from sink extensions to ease discovery, but enabling logger sinks is done in GameServerModule entirely,
therefore adding <add key="serilog:using:File" value="Serilog.Sinks.File" /> and so on is not needed or recommended.
This hybrid configuration was done because not all settings can be configured directly in App.config file.

System name is extracted from log's SourceContext, which is most of the time target class' namespace:
It's Physics for GameServer.Physics or Chat for GameServer.Systems.Chat.
In some places it is overriden ad hoc with class from namespace of expected system.
For example _logger.ForContext<AbilitySystem>().Debug(...) in CombatController will belong to Aptitude system,
because full name of class used in ForContext is GameServer.Aptitude.AbilitySystem.

System overrides can be defined in GameServer.Logging.LogSystemEnricher.
For now I've added only { "Shared.Udp.PacketServer", "Network" }
to assign verbose logs from Channel, NetworkClient, and other classes using logger from PacketServer, to Network system.

Seq is log server/viewer tool, can be used to search and filter logs by systems or any parameter appearing in log message, it's free to use locally.
I've added compose file with its container, to start it run docker compose -p pin -f docker/compose.yaml up -d
Seq UI will be available at http://localhost:8081, admin auth is disabled by default.
To change log level dynamically select "Data -> Ingestion" from the top right menu, then click on "Unathenticated" and choose new "Minimum level", then save.
To list all logs from Aptitude type System = 'Aptitude'; to list all systems of sent logs use select distinct(System) from stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant