Fix #2729 - Remove illegal characters from log before export

Fixes #2729.
See #2729 for discussion on ways to solve the problem.