Why does Rebex.Syslog.client.Send(msg) show prepending "[some unprintable chars]" to msg?

0 votes
asked Sep 17, 2020 by ryan-ag (120 points)

from the example:

msg.Text = "Hello from Syslog client.";

// send message(s)

on the syslog server side, it shows up as "[unprintable chars]Hello from Syslog Client."

This is on 2 different syslog servers and 2 different syslog server products and using the latest beta.

why is this happening?

1 Answer

0 votes
answered Sep 17, 2020 by Lukas Matyska (59,010 points)

The unprintable characters at the beginning of the message are probably UTF-8 BOM.

Please note that RFC 5424 suggest to use UTF-8 with BOM by default. See section 6.4:

The character set used in MSG SHOULD be UNICODE, encoded using UTF-8 as specified in [RFC3629].
If a syslog application encodes MSG in UTF-8, the string MUST start with the Unicode byte order mask (BOM), which for UTF-8 is ABNF %xEF.BB.BF.

At the current version, there is no option to disable UTF-8 BOM. However, BOM is emitted for utf-8 encoding only. If you set SyslogMessage.TextEncoding to any other value (e.g. Encoding.ASCII) the UTF-8 BOM is not emitted.

Alternatively, you can create and use your own UTF-8 encoding like this:

private class MyUtf8Encoding : System.Text.UTF8Encoding
    public override string WebName { get { return "my-utf-8"; } }
    public override int CodePage { get { return 65002; } }
commented Sep 17, 2020 by ryan-ag (120 points)
Thank you for the answer.  I have corrected the UTF-8 BOM problem.