Diagnostic Logger for Unity

Learn more about enabling SDK logging to help troubleshooting.

Sentry's SDK includes its own internal logger to report diagnostics that may be useful when troubleshooting your Sentry configuration.

In the editor window (Tools > Sentry), the diagnostic logs are controlled by Enable Debug Output, Only In Editor and Verbosity Level. By default, debug output is on and limited to the Editor, at the Warning level. Uncheck Only In Editor to also get the logs in builds.

To set the same options in code, use an option configuration script or a manual SentrySdk.Init:

Copied
using Sentry;
using Sentry.Unity;

public class SentryOptionConfiguration : SentryOptionsConfiguration
{
    public override void Configure(SentryUnityOptions options)
    {
        // Enable debug mode to write diagnostic messages
        options.Debug = true;

        // Log everything, from the most verbose level up
        options.DiagnosticLevel = SentryLevel.Debug;
    }
}

The SDK writes its diagnostic logs to Unity's log, tagged Sentry. They show up in the Editor's Console window, in the Player log of a build, and in logcat or the Xcode console on mobile. They aren't sent to Sentry.

To write the logs somewhere else, set the DiagnosticLogger option. The SDK only uses a custom logger while Debug is on.

For example, FileDiagnosticLogger writes diagnostic messages to a file at the path you specify:

Copied
using Sentry.Infrastructure;
using UnityEngine;

// ...
options.Debug = true;
#if !UNITY_EDITOR
// The option configuration script also runs in the Editor during builds,
// so only create the file logger in the game itself.
options.DiagnosticLogger = new FileDiagnosticLogger(
    System.IO.Path.Combine(Application.persistentDataPath, "sentry-log.txt"));
#endif
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").