Logging (Serilog) - UltraStar-Deluxe/Play GitHub Wiki
UltraStar Play uses Serilog as logging library.
See also the wiki page for the log file location.
Using Serilog
The Serilog logger has been configured in Log.cs
and can be accessed using static methods.
Note that the log statement is not executed, depending on the configured log level. This is why a lambda is passed as argument instead of a plain string.
public class MyLoggingBehaviour : MonoBehaviour
{
private void Start()
{
Log.Verbose(() => "Serilog verbose log message");
Log.Debug(() => "Serilog debug log message");
Log.Information(() => "Serilog info log message");
Debug.Log("Unity info log message");
Log.Warning(() => "Serilog warning log message");
Debug.LogWarning("Unity warning log message");
Log.Error(() => "Serilog error log message");
Debug.LogError("Unity error log message");
Log.Exception(() => new Exception("Serilog exception log message"));
Debug.LogException(new Exception("Unity exception message"));
}
}
Logging Targets (Sinks)
Serilog will pass the log message to each of its configured logging targets, which are called sinks (ILogEventSink
).
For the current configuration, see Log.cs
:
-
Rolling file
- Logs are saved to
Application.persistentDataPath + "/Logs"
- Log file changes daily
- Max 5 files
- Max 250 MB per file
- Logs are saved to
-
UnityLogEventSink
- Logs are passed to Unity's Console
Note that
- Unity's logging methods (
Debug.Log
and related) are also passed to Serilog (viaApplication.logMessageReceived
)- Thus, you can also use
Debug.Log
as usual and use Serilog only for advanced features (structured logging).
- Thus, you can also use
- Serilog logging is also passed to Unity's logging (via
UnityLogEventSink
).- Thus, logging statements done with
Log.Logger
are also visible in the Unity Console. - To prevent cycles, a marker is added to the log message (depending on the original source this is
unityLogEventSinkMarker
orskipUnityLogEventSinkPropertyName
)
- Thus, logging statements done with