[5.0] Log exceptions and their messages when a job fails.

Recreated this pull request for 5.0 instead of 4.2.

Fixes issue #6203.
This might be more readable:

```php
$exception = new RuntimeException(sprintf('Max tries of %d attempted.', $maxTries));

return $this->logFailedJob($connection, $job, $exception);
```