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:
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;
}
}
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:
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
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
Warning
The FileDiagnosticLogger implementation will overwrite any existing file, and will grow indefinitely. You should avoid using it long-term in a production environment.
FileDiagnosticLogger keeps its file open until the process exits, and creating a second logger for the same file can throw. If several instances of the game can run at once, give each its own file name. Don't use it with Application.persistentDataPath on Nintendo Switch or Xbox, where the SDK itself doesn't write to that path.
You can also create your own diagnostic logger class, either by implementing the IDiagnosticLogger interface, or inheriting from the DiagnosticLogger abstract class and overriding the LogMessage method.
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").