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

Unity editor will not response if I used AddZLoggerRollingFile and dispose #18

Closed LacusCon closed 3 years ago

LacusCon commented 4 years ago

//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();
        };
    }
neuecc commented 3 years ago

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

neuecc commented 3 years ago

I've released 1.3.0.