Brought excluded code into the scope of a try block in SysLogHandler.emit().
Closes #22776: Merged fix from 3.4.