Search code examples
asp.net-coreserilog

serilog separate events formatted in json by a comma


i am using serilog in asp net core application and using a json formatter to create a daily log file (rolling interval is set to "Day"). When i look at my file each event is itself valid json but the file in a whole is not which makes looking at it in something like code beautify impractical. Is there a way to tell the serilog to add a comma between the events so that the file will be valid.


Solution

  • I think you are incorrect when you say that your log file would conform to json if commas separated each line. A valid json document would either start with { and describe an object, or start with [ and describe an array. Either way, you would have to close the document, and only then it would be valid json. Now to the million dollar question: how would you know when to close the document even if you wrote your own text formatter?

    I think you should treat each log event as a valid json object, and use a tool and product that supports it.