-
Notifications
You must be signed in to change notification settings - Fork 125
Flush to disk option #20
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
Conversation
…d file sink tests.
CC @pakrym |
/// A sink wrapper that periodically flushes the wrapped sink to disk. | ||
/// </summary> | ||
/// <typeparam name="TSink">The type of the wrapped sink.</typeparam> | ||
public class PeriodicFlushToDiskSink<TSink> : ILogEventSink, IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why generic? To avoid interface method invocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not so keen on this upon second thoughts. It is to make clear that the passed-in ILogEventSink
should also be IFlushableFileSink
(no union types in C#) but the code would be a bit nicer to read if non-generic and tested at runtime. Going to change this.
LGTM |
Okay, I'm going to make a couple of minor tweaks this morning, then push through a |
Initially the file sink of Serilog didn't have the ability to flush to disk at specified intervals. This was brough in a newer version (see serilog/serilog-sinks-file#20).
Initially the file sink of Serilog didn't have the ability to flush to disk at specified intervals. This was brough in a newer version (see serilog/serilog-sinks-file#20).
Fixes #18 (rolling file support needed downstream).
Attempts to optimize things a bit so no flush is performed unless events have been written.
The
IFlushableFileSink
andPeriodicFlushToDiskSink<T>
are (reluctantly) public, as this will permit the downstreamRollingFileSink
to wire up to the same mechanism, without us having to encapsulate the periodic flushing behavior inFileSink
andSharedFileSink
directly. In the long run, we might get some kind of generializedIFlushable
into the base Serilog package and make it available across the board through some kind of generic wrapper.I verified by hand that the
FlushToDisk()
is called, but can't come up with an easy way to test it without some kind of multi-process runner. If we query the file size from Windows from the unit test process, it'll always report a consistent view of the world to us :-).Bonus: discovered the shared file sink tests were inadvertently ignored 😢; after enabling, found a bug preventing size limiting from taking effect. Fixed this too.