-
Notifications
You must be signed in to change notification settings - Fork 125
Flush-to-disk option #18
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
Comments
Thank for the note. Full sync-to-disk is very, very slow (order of milliseconds). I've been hesitant to add the option because in most apps it'll be unacceptable. The current behavior is to flush through to the OS page cache, which, while it won't protect from data loss in a power outage (very little can), deals with process crashes and the like. In your scenario, would the perf hit be acceptable? Is the concern data loss, or is OMS the primary driver for needing this? Cheers! |
Hi! This is my problem detail.
I found another way to write to disk almost immediately. var file = File.Open("log.txt", FileMode.Append, FileAccess.Write, FileShare.Read);
var writer = new StreamWriter(file, <encoding>);
writer.Write("Some string");
writer.Flush();
file.Flush(true); // this It's very helpful if my problem will be solved by the library, but I know it is difficult problem for the library... Thanks |
@nblumhardt we have the same issue while using Serilog for Azure AppServices logging, Log Stream feature picks up changes only when logs file size is increased. Azure AppServices file logging is intended as temporary thing that you turn on to debug you application live, so we are somewhat fine with taking a performance hit although it would be better to flush events in batches with a short timeout rather then each time. Other solution is to have timer and open/close file for reading in parallel which will also force OS to flush the data/update attributes. |
@pakrym thanks for the info, sounds like this is something we'll need to accommodate. A simple wrapper that closed/reopened the file by disposing/re-creating the sink on a timer could be implemented atop what's there now, but doesn't seem like a long-term option. Going one step further might look like:
Sound like a plan? |
Sounds like exactly what we need! |
@nblumhardt what's your plan on timeline of this? I can do a PR if you have something on you list already. We are pretty anxious to get this in because it blocks one of the main features of integration. |
@pakrym I'll take a quick look now; if I can get something together quickly it might be easier if I coordinate it, but if not, a PR would be welcome. Will let you know later today. Thanks! |
…d file sink tests.
👀 |
Going to reopen this until we're comfortable it's all covered. |
Hrm, thought I was pushing to my fork, but nope, pushed to CI was clean, rolling file support now published as https://www.nuget.org/packages/Serilog.Sinks.RollingFile/3.1.0-dev-00745. |
@nblumhardt everything seems to work well with this change. Thank you. |
We'll let this bake a short while before releasing as stable - let me know if there's any urgency around getting a non-prerelease version up. Cheers! |
@nblumhardt Thanks! How long are you planning to keep this baking? We'll be depending on this in our 1.1 release :) |
@muratg I'll put some time aside on Monday to upgrade some apps and test more rigorously. Considering it's an "opt-in" feature there's no great danger in putting it out there, ideally we'll just be confident that it works :-) .. If I can't break it, I'm happy to push the button 👍 |
@nblumhardt Awesome, thanks! |
In Windows 10 and Windows Server 2012 R2, StreamWriter.Flush won't write the data to disk immediately.
You can know this by running under code and watching the file size through "dir" command.
We can write to disk immediately by touching the file like this.
Could you please improve "buffered:false" or add new option to do this?
P.S.
I'm using Serilog.Sinks.RollingFile for windows service logging, and collecting the logs by Microsoft Operations Management Suite (OMS). I found OMS log collection is not working good, because above.
The text was updated successfully, but these errors were encountered: