Revise the method of file size limiting #13
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While investigating datalust/serilog-sinks-seq#28, I found a few unsatisfactory things lurking in the way this sink limits file size:
(The counting machinery is necessary because
FileStream.Length
is an expensive call in comparison.)This PR is an attempt to address these things. Primarily, it moves from a "character limiting text writer" to a "length counting stream wrapper". The sink uses knowledge of the count to decide whether or not to write whole events instead of letting the last event be truncated.
Some caveats:
Perf benefit: despite timings being I/O bound, the included sample program that writes 1M events to a non-buffered, size-limited log file completes with the new version in 0.93x the execution time of the current RTM sink (~13700 ms vs ~14300 ms, i7/SSD).
@serilog/reviewers-core more eyes the merrier on this one! :-)