Skip to content

KuraiAndras/Serilog.Sinks.Unity3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Unity3D

openUPM

Serilog sink for Unity3D, logs to Unity Debugger

Usage

Installation

Install it through OpenUPM or use the UnityPackage from the Releases page.

openupm add com.serilog.sinks.unity3d

Dependencies

You need add Serilog1 to your project. Your usual options:

Creating the logger

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)

Unity log extras

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");
    }
}

Migration guide

For versions before 2.0.0

Set up MainThreadDispatcher.Unity

Upgrade from 1.0.0 to 1.0.1

You need to provide the following DLLs:

  • Serilog
  • MainThreadDispatcher

Footnotes

  1. Version 2.12.0 or later

  2. This is done with a new extension method override which explicitly accepts UnityEngine.Object.