Using Crashlytics LogException for all non fatal exceptions

We are using Crashlytics with our game, and would like to log all exceptions that are thrown by Unity.

To get an event for all the exceptions thrown, we are using:

Application.logMessageReceived += HandleLog;

void HandleLog(string msg, string stackTrace, LogType type) {
...
}

The problem is, that the Firebase SDK was changed, and now they expect an Exception object to be passed to their call:

void LogException (Exception exception)

What is the best way to create the exception in such a way that the stack trace will be logged correctly?
I have seem several reflection based solutions, but has anyone used something that works with Crashlytics?

I actually find it very weird that they do not have a straight forward solution for this… am I missing something here?

We use that API to report low memory events. We use it like so:

Crashlytics.LogException(new Exception($"{nameof(LowMemoryObserver)} observed system lowMemory event."));

Have you tried just making a fresh exception out of the stackTrace string?

1 Like

You can subclass Exception to take in the message and stacktrace provided by Unity.