Log errors to the database.