Log exceptions to database