Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unity editor will not response if I used AddZLoggerRollingFile and dispose

LacusCon opened this issue · comments

//Unity ver: 2019.1.14
// step 1 : use AddZLoggerRollingFile
// step 2: use log print(ZLogTrace, ZLogWarning
// step 3: use dispose
// operation: change unity run mode from play to stop
// result: unity not response

static LogManager()
    {
        // Standard LoggerFactory does not work on IL2CPP,
        // But you can use ZLogger's UnityLoggerFactory instead,
        // it works on IL2CPP, all platforms(includes mobile).
        loggerFactory = UnityLoggerFactory.Create(builder =>
        {
            // or more configuration, you can use builder.AddFilter
            builder.SetMinimumLevel(LogLevel.Trace);

            // AddZLoggerUnityDebug is only available for Unity, it send log to UnityEngine.Debug.Log.
            // LogLevels are translate to
            // * Trace/Debug/Information -> LogType.Log
            // * Warning/Critical -> LogType.Warning
            // * Error without Exception -> LogType.Error
            // * Error with Exception -> LogException
            builder.AddZLoggerUnityDebug();

            // and other configuration(AddFileLog, etc...)

        //TODO step 1
  	builder.AddZLoggerRollingFile((offset, i) => $"Debug_Logs/{DateTime.Now.ToLocalTime():yyyy-MM-dd}_{i:000}.log",  x => x.ToLocalTime().Date, 1024);
        });

        globalLogger = loggerFactory.CreateLogger("Global");

        Application.quitting += () =>
        {
            // when quit, flush unfinished log entries.
            //TODO step 3
            loggerFactory.Dispose();
        };
    }

Thanks, I've found bug.
Fix quickly and release soon.

I've released 1.3.0.