codeAPI Reference
Sandbox.Log
Sandbox.Log
Static logging class for console output.
Overview
Log messages appear in the editor console, in-game console (press ~), and log files.
Logging Methods
CSHARP
// Information
Log.Info($"Player joined: {playerName}");
// Warning
Log.Warning("Low ammo!");
// Error
Log.Error("Failed to load save");Custom Loggers
CSHARP
public static Logger GameLog = new("Game");
public static Logger NetLog = new("Network");
// Usage
GameLog.Info("Game starting");
NetLog.Warning("Connection unstable");
NetLog.Error("Desync detected");Console Commands
View logs in-game:
CODE
~ // Open console
clear // Clear consoleLog Levels
| Level | Use For |
|---|---|
| Info | General information |
| Warning | Potential issues |
| Error | Problems that need attention |
| Verbose | Detailed debugging (filtered) |
Performance
Remove debug logs in release:
CSHARP
#if DEBUG
Log.Info($"Debug: {expensiveCalculation}");
#endifString Interpolation
CSHARP
// Modern C# string interpolation
Log.Info($"Health: {Health}, Position: {WorldPosition}");
// Complex formatting
Log.Info($"Time: {Time.Now:HH:mm:ss}");Related
- DebugOverlay — Visual debugging
- Gizmo.Draw — Editor visualization
Was this helpful?