Docs Menu

Docs HomeRealm

Handle Sync Errors - .NET SDK

On this page

  • Set the Client Log Level
  • Customize the Logging Function

Device Sync represents errors via SessionExceptions. In addition to the standard exception properties, you have access to an ErrorCode that contains information about the type of the error and allows you to have strongly typed handling logic.

config.OnSessionError = (session, sessionException) =>
switch (sessionException.ErrorCode)
case ErrorCode.InvalidCredentials:
// Tell the user they don't have permissions to work with that Realm
case ErrorCode.Unknown:
// See
// /latest/reference/Realms.Sync.Exceptions.ErrorCode.html
// for all of the error codes


Additional Exception Information

For security reasons, App Services may send only a minimal amount of information about an exception, but the server-side logs will contain more details. In these cases, the HelpLink property on the exception contains a link to the associated log entry.


For a list of common Device Sync errors and how to handle them, refer to Sync Errors in the App Services Device Sync documentation.

To control which messages are logged by the client logger, use LogLevel:

Logger.LogLevel = LogLevel.Debug;


To diagnose and troubleshoot errors while developing your application, set the log level to debug or trace. For production deployments, decrease the log level for improved performance.

To set a custom logger function, set Logger.Default to a custom Logger function.

using Realms.Logging;
Logger.LogLevel = LogLevel.All;
// customize the logging function:
Logger.Default = Logger.Function(message =>
// Do something with the message
←  Manage Flexible Sync Subscriptions- .NET SDKClient Resets - .NET SDK →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.