Esempio n. 1
0
 private void SaveExceptionFile(Directory directory, string fileName, Exception exception)
 {
     try
     {
         using (var fileStream = NewFileStream(Path.Combine(directory.FullName, fileName), FileMode.Create))
         {
             var formatter = new BinaryFormatter();
             formatter.Serialize(fileStream, exception);
         }
         AppCenterLog.Debug(Crashes.LogTag, $"Saved exception in directory {ErrorStorageDirectoryName} with name {fileName}.");
     }
     catch (Exception e)
     {
         if (!exception.GetType().IsSerializable)
         {
             // Note that this still saves an empty file which acts as a marker for error report life cycle. Same as Android SDK.
             AppCenterLog.Warn(Crashes.LogTag, $"Cannot serialize {exception.GetType().FullName} exception for client side inspection. " +
                               "If you want to have access to the exception in the callbacks, please add a Serializable attribute " +
                               "and a deserialization constructor to the exception class.");
         }
         else
         {
             AppCenterLog.Warn(Crashes.LogTag, "Failed to serialize exception for client side inspection.", e);
         }
     }
 }
Esempio n. 2
0
        private void EnsureDatabaseDirectoryExists()
        {
            var databaseDirectoryPath = Path.GetDirectoryName(_databasePath);

            if (string.IsNullOrEmpty(databaseDirectoryPath))
            {
                return;
            }
            try
            {
                var databaseDirectory = new Directory(databaseDirectoryPath);
                if (!databaseDirectory.Exists())
                {
                    databaseDirectory.Create();
                }
            }
            catch (Exception e)
            {
                // Not throwing this exception (and not handling it along with DB access error) since there are scenarios when SDK might fail to access database path, but opens database file just fine.
                // So the logic here is only to make sure that directory to contain db file exists - DB file access handled separately.
                AppCenterLog.Error(AppCenterLog.LogTag, "Failed to create database directory.", e);
            }
        }