Logging
Levels
LogLevel.Debug // 0
LogLevel.Info // 1
LogLevel.Warning // 2
LogLevel.Error // 3
LogLevel.Assert // 4
Methods
Log.Debug("message");
Log.Info("message");
Log.Warning("message");
Log.Error("message", throwException: false);
Log.Error<InvalidOperationException>("message");
Log.Assert(condition, "message");
All capture the caller's file path and line number.
Return value
Each call returns a LogMessage:
LogMessage msg = Log.Info("Hello");
Debug.Log(msg.Created); // DateTime
Debug.Log(msg.Level); // LogLevel
Debug.Log(msg.File); // source path
Debug.Log(msg.Line); // line number
Debug.Log(msg.Message); // the message
Debug.Log(msg.StackTrace); // StackTrace
Async
Thread-safe. Works from any thread:
await Task.Delay(500);
Log.Info("From background thread");
Global hook
LogContainer.OnLog += msg =>
Debug.Log($"{msg.Level}: {msg.Message}");