Log network and unexpected exceptions if logging is enabled.

Closes #275.