9

If someone can please help me with my Serilog configuration. I would like to know is it possible to configure the rolling file sink to always output a file with a valid JSON. The file structure has to be an array of JSON items which looks like this:

If the log file is empty, the contents should be:

[]

If the log file stores a single item, the contents should be:

[{some.json}]

If the log file stores n items, then the contents should be:

[{some json}, {...}, {n-th json}]

The log file should never look like:

[{some json}, 

or

{some json}
{some json}

or

{some json},
{some json},

Thanks in advance.

magic
  • 229
  • 3
  • 6
  • 11
  • 2
    Any reasonable json log processor would not force this format (and serilog has no facilities around this) - you want to be able to forward one by one, and processing this as an array forces the entire set to be processed as a single in memory tree. If you did insist on doing this, you'd have a messy rewriting race to control (and the only way to read it would be to completley block all writes until the reader has taken a cut) – Ruben Bartelink Sep 26 '18 at 00:22
  • This seems like a bad idea since normally you would like to append text to a file for performance reasons, but your solution would require to move the final ] at every write. Can you change the behavior of the reader instead? – FantasticFiasco Oct 19 '18 at 05:26
  • 2
    I up voted this question because if someone reads that Serilog outputs json then they would rightly expect the output to validate in json lint. Yet, it's not valid json and can't be easily deserialized.for use in an app. They should make this clear in their documentation as it's very misleading. – Yogi Oct 05 '19 at 06:32

0 Answers0