Closed markusschaber closed 1 year ago
Hi @markusschaber,
You can pass JsonWriterOptions
to the logger using this configuration overload as follows:
builder.Logging.AddJsonFile(textBuilder: new JsonFileLogEntryTextBuilder(jsonWriterOptions), configure: o => { /* ... */ });
For further customization, you can subclass JsonFileLogEntryTextBuilder
and pass an instance of that to the method above. For example, to remove the trailing comma, you'll need to override the BuildEntryText
method.
Would you implement the changes, or accept patches, to enable JSON lines support?
Improvements are welcome!
FYI: in the latest version (v3.5.0), I added some convenience methods along with an option class so you don't need to subclass JsonFileLogEntryTextBuilder
any more if you just want to change the separator between entries:
builder.Logging.AddJsonFile(new JsonFileLogFormatOptions { JsonWriterOptions = new JsonWriterOptions { Indented = false }, EntrySeparator = "" }
Hi, I'm evaluating Karambolo.Extensions.Logging.File.Json and the README states:
But while experimenting, I found some small differences to
AddJsonConsole()
.First, it looks like Karambolo separates entries with a ',', while the console logger only uses line break.
Second, the
JsonConsoleFormatterOptions
acceptJsonWriterOptions
, where we can set 'Indented = false
'.This combination allows us to write the JSON lines (aka NDJSON) format, each log entry on a single line, with the console logger.
Would you implement the changes, or accept patches, to enable JSON lines support?