Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EcsTextFormatter use of BaseStream results in unbuffered writes which causes out of order writes to file in Serilog #135

Closed
Jhaiii opened this issue Mar 17, 2021 · 1 comment · Fixed by #144
Labels
bug Something isn't working

Comments

@Jhaiii
Copy link

Jhaiii commented Mar 17, 2021

When writing the formatted json to a Serilog Durable Http Sink (Serilog.Sinks.Http), the log is corrupted as a BOM is written after the first log rather than as the first bytes of the file. The Http Sink in turn uses a file sink to store the buffer before shipping to http endpoint (Logstash in my case). Logstash cannot process the logs due to an embedded BOM.

The cause of the issue comes down to the EcsTextFormatter writing directly to the base stream rather than the buffer. When the Serilog File Sink flushes the buffer for the first time, the BOM is written after the first log rather than being the first bytes.

ecsEvent.Serialize(sw.BaseStream);

Please see Issue raised on Serilog project where this was discussed, prior to coming to conclusion that EcsTextFormatter should be modified.

To prove this, changing the code to below results in the correct sequence of writes:
output.Write(ecsEvent.Serialize());

@russcam russcam added the bug Something isn't working label May 28, 2021
@russcam
Copy link
Contributor

russcam commented May 28, 2021

Thanks for opening @Jhaiii, looking at now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants