Serilog sink for Unity3D, logs to Unity Debugger
Install it through OpenUPM or use the UnityPackage from the Releases page.
openupm add com.serilog.sinks.unity3d
You need add Serilog1 to your project. Your usual options:
- Xoofx's UnityNuGet server (preferred)
- Manual add the Serilog DLL to your assets folder
- NuGetForUnity
var logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Unity3D()
.CreateLogger();
If you have a custom implementation of Unity's ILogger
interface, then you can log to that:
ILogger myCustomLogger = new MyCustomLogger();
var logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Unity3D(unityLogger: myCustomLogger)
.CreateLogger();
If no logger is provided the library will use UnityEngine.Debug.unityLogger
(which is equivalent of using UnityEngine.Debug.Log()
methods)
You can provide the UnityEngine.Object
context2 and tag parameters for the logger:
public class MyObject : MonoBehaviour
{
// ...
private ILogger _logger = new();
public void DoLog()
{
_logger
.ForContext(this)
.WithUnityTag("My custom tag")
.Information("This is an info log");
}
}
Set up MainThreadDispatcher.Unity
You need to provide the following DLLs:
- Serilog
- MainThreadDispatcher