DnsServer icon indicating copy to clipboard operation
DnsServer copied to clipboard

LogExporterApp: Syslog target double-wraps messages in RFC5424 (message is fully RFC5424-formatted twice)

Open jusicgn opened this issue 2 months ago • 8 comments

Component: Apps/LogExporterApp, SyslogExportStrategy.cs Version: LogExporterApp 3.0.1

Summary

When the Syslog target of the Log Exporter app is enabled, every exported message is formatted as a complete RFC5424 syslog message twice. The _msg payload that ends up on the wire contains a full, nested RFC5424 syslog message (with its own header and structured data) inside the outer syslog message body.

Root cause

In SyslogExportStrategy.ExportAsync():

public Task ExportAsync(IReadOnlyList<LogEntry> logs)
{
    foreach (LogEntry log in logs)
        _sender.Information(_formatter.FormatMessage((LogEvent?)Convert(log)));

    return Task.CompletedTask;
}

Convert(log) builds a LogEvent with the query fields as structured properties and a message template. This LogEvent is then rendered manually via Rfc5424Formatter.FormatMessage(...) into a complete, already-finished RFC5424 string (own PRI, timestamp, hostname, app-name, proc-id, and [meta ...] structured data).

That finished string is then passed as plain text to _sender.Information(...). _sender is itself a Serilog syslog sink (UdpSyslog / TcpSyslog / LocalSyslog) configured with SyslogFormat.RFC5424, which formats the message as RFC5424 again — wrapping the already-formatted inner message inside a second, outer RFC5424 envelope.

Actual behavior

Received syslog message (example, IPs/domains anonymized):

<182>1 2026-01-01T12:00:00.000000+00:00 dns-host TechnitiumDNSServer 1234 - [meta timestamp="2026-01-01T12:00:00.000Z" clientIp="203.0.113.10" protocol="Udp" responseType="Recursive" responseRtt="12.3" rCode="NoError" qName="example.com" qType="A" qClass="IN" questionsSummary="QNAME: example.com, QTYPE: A, QCLASS: IN" aName_0="example.com" aType_0="A" aClass_0="IN" aTtl_0="60" aRData_0="203.0.113.20" aDnssecStatus_0="Unknown" answersSummary="203.0.113.20"] "QNAME: example.com, QTYPE: A, QCLASS: IN"; RCODE: "NoError"; ANSWER: ["203.0.113.20"]

Everything from <182>1 2026-01-01T... onward is itself a fully formed RFC5424 message, sitting inside the MSG part of the outer one. Any log receiver that parses standard RFC5424 (e.g. rsyslog, VictoriaLogs) only sees the outer envelope and gets the entire inner message as one opaque text blob — the [meta ...] fields are not exposed as structured data to the receiver, only recoverable by re-parsing the message body manually.

Expected behavior

A single, correctly formed RFC5424 message per query, with the query metadata exposed as top-level structured data (SD-ID) — not double syslog-wrapped.

Suggested fix

Don't pre-render the LogEvent with Rfc5424Formatter before handing it to the sink. Instead, either:

  • pass the message template and properties directly to _sender.Information(...) and let the already-configured SyslogFormat.RFC5424 sink do the formatting once, or
  • if the [meta ...] structured-data block is specifically wanted, configure the sink's own formatter/structured-data support instead of building it manually via Rfc5424Formatter beforehand.

Happy to test a fix against our setup (two DNS Server 15.5 instances, Linux, TCP syslog target) if useful.

jusicgn avatar Sep 22 '26 00:09 jusicgn

Thanks for the feedback. I haven't checked this in details but changing it output format will cause issues for people already using the app.

I think @zbalkan will be in better position to check this issue.

ShreyasZare avatar Sep 22 '26 05:09 ShreyasZare

I'll check it out. Thanks for tagging me.

zbalkan avatar Sep 22 '26 06:09 zbalkan

I was just looking into this same issue as I was just setting up a cluster of servers for my house! Happy to delete the draft issue that I was totally going to finish his weekend... 😅

It does look like this has been around for a while, as I stumbled across this blog post describing this broken behavior back in January: https://nathanmark.us/debugging-a-double-encoded-syslog-issue-with-technitium-dns-server/

Additionally, it does look like the "Actual behavior" section doesn't accurately reflect the actual syslog messages emitted from the DNS server (idk if the AI mangled it).

This is a full example of a problem syslog packet (sent from DnsServer 15.5, Log Exporter 3.1) as seen by a packet capture:

<182>1 2026-09-25T18:42:06.644644+00:00 DNS-02 TechnitiumDNSServer 1 - - <182>1 2026-09-25T18:42:02.748641+00:00 DNS-02 TechnitiumDNSServer 1 - [meta timestamp="2026-09-25T18:42:02.748Z" clientIp="10.240.9.102" protocol="Udp" responseType="Recursive" responseRtt="25.407400000000003" rCode="NoError" qName="mirror-test.teal.party" qType="A" qClass="IN" questionsSummary="QNAME: mirror-test.teal.party, QTYPE: A, QCLASS: IN" aName_0="mirror-test.teal.party" aType_0="CNAME" aClass_0="IN" aTtl_0="300" aRData_0="mirror.nodesdirect.com." aDnssecStatus_0="Insecure" aName_1="mirror.nodesdirect.com" aType_1="A" aClass_1="IN" aTtl_1="99" aRData_1="23.92.92.94" aDnssecStatus_1="Insecure" answersSummary="mirror.nodesdirect.com., 23.92.92.94"] "QNAME: mirror-test.teal.party, QTYPE: A, QCLASS: IN"; RCODE: "NoError"; ANSWER: ["mirror.nodesdirect.com., 23.92.92.94"]

Thanks for the feedback. I haven't checked this in details but changing it output format will cause issues for people already using the app.

I think @zbalkan will be in better position to check this issue.

I do agree that changing the format of the syslog messages may cause issues for existing implementations but I do encourage this to be addressed as this syslog-in-syslog stuff is a mess to deal with for new setups (and is clearly not desired behavior). Hopefully those who are already using it have adapted their syslog processing to just un-wrap the outer syslog message and re-process it which should gracefully handle this being fixed. If a breaking change is of high concern, could a "format" config option could be introduced that defaults to the legacy format but allows for opting-in to the standard rfc5424-compliant format?

hmhackmaster avatar Sep 25 '26 18:09 hmhackmaster

Hi all,

I'm working on a small patch. I need to test the edge cases but it works for my basic cases. If you'd like to try, here's the branch: https://github.com/zbalkan/DnsServer/tree/fix/logexporter-syslog-rfc5424

zbalkan avatar Sep 25 '26 19:09 zbalkan

Hi @zbalkan, would love to test it but need a way to install it in my running Technitium instance. I tried zipping the source folder directly, but that doesn't produce a loadable app (Technitium expects the compiled DLL, not the .cs sources). Do you have an installable ZIP at hand or could provide one?

jusicgn avatar Sep 26 '26 11:09 jusicgn

Hi,

I'll test it today and provide the patch, and zip attached for you to try if you'd like to try as well. I'm away from keyboard for it. But it's doable of course.

zbalkan avatar Sep 26 '26 11:09 zbalkan

Hi @hmhackmaster,

If a breaking change is of high concern, could a "format" config option could be introduced that defaults to the legacy format but allows for opting-in to the standard rfc5424-compliant format?

While I agree that backwards compatibility matters, aligning well with a broken state should not be considered "legacy", IMHO. Therefore, it's better to warn the users clearly in the next release, so that they can get rid of the hacks.

https://nathanmark.us/debugging-a-double-encoded-syslog-issue-with-technitium-dns-server/

It's very counterintuitive to write a blog but not writing an issue and get it fixed. I'd have gotten this fixed sooner and help people waste time with hacks.

zbalkan avatar Sep 28 '26 07:09 zbalkan

I just noticed an update (3.0 to 3.1) of the LogExporterApp was available, but it doesn't seem to include #2190 ?

arantius avatar Nov 19 '26 20:11 arantius