Open krisrok opened 9 months ago
I'm not a maintainer, but as a listener on #9, this looks pretty cool! A few thoughts:
BeginScope
then we should also be able to get them in via an enricher, and thus not force people to create log scopes everywhere they log. Maybe I'm mistakenILoggerFactory.Add*
extension method? Coming from the WPF and ASP.NET worlds, I've never seen a helper library like this that couldn't work with AddSerilog
...MainThreadDispatcher
package), so I'm not sure why that changed. Even if the MainThreadDispatcher
dependency is not added back, its logic could be replicated in the Unity3DLogEventSink
(it's literally only like 100 lines).Pinging @KuraiAndras for visibility on this PR.
The earliest when I can take a look is around sunday
Based on the discussion in #9, here's support for using
UnityEngine.Object
s withBeginScope()
and using the latest pushed scope as context when sending following log entries to Unity's console window.This way, log entries are clickable and e.g.
GameObject
s get pinged in the editor.On key design choice from a user's perspective was to avoid additonal APIs or dependencies. User code only needs to reference
Microsoft.Extensions.Logging.ILogger
and work with the abstractions. Everything else is done upfront via configuration.Example
Config:
Usage:
Async/await support
It also works with async/await code as long as it is managed by Unity's main thread. UniTask should work fine, too.
No thread safety for UnityEngine.Objects
This stems from the known Unity limitation: Access to all/most members of its managed-lifecycle objects is limited to the main thread.
So when calling e.g.
BeginScope(gameObject)
on other threads the library throws anNotSupportedException
to keep it from failing somewhere else down the line (like in enrichers or sinks).Everything else works fine from other threads.
Optional integration
The new functionality lives in a separate assembly (
Serilog.Sinks.Unity3D.Extensions.Logging
). The assembly definition makes sure it only compiles when the dependencies are in place, namely the packageorg.nuget.serilog.extensions.logging
(which in turn depends on Serilog and Microsoft's abstractions).If the dependencies are not found, the base sink (Serilog.Sinks.Unity3D) still works just like before.
Installation via manifest.json