Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Sync Data

Handle Sync Errors and Timeouts - .NET SDK

La sincronización del dispositivo representa errores a través de Excepciones de sesión. Además de las propiedades de excepción estándar, tiene acceso a un código de error que contiene información sobre el tipo de error y le permite implementar una lógica de gestión fuertemente tipada.

config.OnSessionError = (session, sessionException) =>
{
switch (sessionException.ErrorCode)
{
// See https://www.mongodb.com/es/docs/realm-sdks/dotnet/latest/reference/Realms.Sync.Exceptions.ErrorCode.html
// for a list of all error codes
case ErrorCode.BadQuery:
break;
}
};

Nota

Additional Exception Information

Por razones de seguridad, los Servicios de Aplicaciones pueden enviar solo una cantidad mínima de información sobre una excepción, pero los registros del servidor contendrán más detalles. En estos casos, el HelpLink La propiedad de la excepción contiene un enlace a la entrada de registro asociada.

Tip

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;

Tip

Para diagnosticar y solucionar errores mientras desarrolla su aplicación, configure el nivel de registro en debug o trace. Para implementaciones de producción, reduzca el nivel de registro para mejorar el rendimiento.

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
});

During Sync sessions, events may timeout without throwing an exception. You can set the CancelAsyncOperationsOnNonFatalErrors to true so that these events throw an exception that you can then handle. The following code shows an example of setting the CancelAsyncOperationsOnNonFatalErrors property, and 3 events that will throw an exception if they timeout:

var config = new FlexibleSyncConfiguration(app.CurrentUser!)
{
CancelAsyncOperationsOnNonFatalErrors = true,
};
// These operations will throw an exception
// on timeout or other transient sync session errors.
var realm = await Realm.GetInstanceAsync(config);
var session = realm.SyncSession;
await session.WaitForUploadAsync();
await session.WaitForDownloadAsync();

Volver

Administrar suscripciones de sincronización flexible

En esta página