Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.14k stars 80 forks source link

Zlogger throws exception when using Unity Editor Playback Options #46

Closed Kevdome3000 closed 2 years ago

Kevdome3000 commented 3 years ago

Hey there,

Just an observation, but I'm using a Global logging manager like the example provided in the Readme, and I get NullReference errors when stopping and re-entering play mode.

Here is an example stack trace:

[Exception] NullReferenceException: Object reference not set to an instance of an object
ZLoggerExtensions.ZLogInformation() at Library/PackageCache/com.cysharp.zlogger@1.5.0/ZLoggerExtensions.cs:4757
4755:   public static void ZLogInformation(this ILogger logger, EventId eventId, Exception exception, string message)
4756:   {
-->4757:       logger.Log(LogLevel.Information, eventId, new MessageLogState<object>(null, message), exception, (state, ex) =>
4758:       {
4759:           return state.Message;

ZLoggerExtensions.ZLogInformation() at Library/PackageCache/com.cysharp.zlogger@1.5.0/ZLoggerExtensions.cs:4742
4740:   public static void ZLogInformation(this ILogger logger, string message)
4741:   {
-->4742:       ZLogInformation(logger, default(EventId), default(Exception), message);
4743:   }

AppManager.Start() at /XXXX/Managers/App/AppManager.cs:84
82:   public void Start()
83:   {
-->84:       _logger.ZLogInformation("----- AppManager Initialized");
86:       // userContainer.SetActive(true);

Maybe this is expected, but it would be cool if it worked with the editor play options.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.