Skip to content

Logging

Алексей . edited this page Mar 21, 2026 · 4 revisions

Logging

Architecture

SF-Arizona uses a two-layer logging system:

  1. SFLog — low-level background file writer (source)
  2. SFLoggerProvider — ILoggerProvider bridge for modules (source)

All log entries are written to sf_arz.log next to gta_sa.exe via a dedicated background thread, ensuring zero blocking on the game thread.

Log Format

Module logs (via ILogger)

[2026-03-22 03:23:08.456] [INFO] [chat-violation-monitor] Violation detected player=John
[2026-03-22 03:23:09.789] [FAIL] [rpc-debugger] Parse error: NullReferenceException
[2026-03-22 03:23:10.012] [WARN] [brightbinder] Target player not found

Format: [timestamp] [LEVEL] [module-id] message

Infrastructure logs (via SFLog directly)

[2026-03-22 03:23:08.123] [INFO] RegisterModule id=dialog-scraper type=DialogScraper
[2026-03-22 03:23:08.124] [ERROR] Module faulted id=my-module: System.NullReferenceException...

Level Tags

LogLevel Tag
Trace TRCE
Debug DBUG
Information INFO
Warning WARN
Error FAIL
Critical CRIT

Only Information and above are logged by default.

Usage in Modules

using Microsoft.Extensions.Logging;

// Available via protected property Log in SFModuleBase:
Log.LogInformation("Module started");
Log.LogWarning("Something unexpected: {Detail}", detail);
Log.LogError(exception, "Failed to process packet");
Log.LogInformation("Player {Name} connected with id={Id}", name, id);

Custom Logger Provider

Override CreateLogger in your module to use Serilog, NLog, or any ILoggerProvider:

[SFModule("my-module", "MyModule")]
public class MyModule : SFModuleBase
{
    protected override ILogger CreateLogger(ModuleContext context)
    {
        // Example with Serilog:
        var serilogLogger = new LoggerConfiguration()
            .WriteTo.File("my-module.log")
            .CreateLogger();
        return new SerilogLoggerFactory(serilogLogger)
            .CreateLogger(context.Descriptor.Id);
    }
}

The default SFLoggerProvider writes to sf_arz.log via the background writer thread.

SFLog Direct API

For infrastructure code outside modules:

SFLog.Info("message");
SFLog.Warn("message");
SFLog.Error("message");
SFLog.Error(exception, "context");
SFLog.WriteFormatted("pre-formatted line");  // raw write
SFLog.Path;  // path to sf_arz.log

Clone this wiki locally