Flush-to-disk option
See original GitHub issueIn 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.
Log.Logger = new LoggerConfiguration()
.WriteTo.File("log.txt")
.CreateLogger();
for (var i = 0; i < 100; ++i)
{
Console.WriteLine(i);
Log.Information("Hello, file logger!");
System.Threading.Thread.Sleep(1000);
}
We can write to disk immediately by touching the file like this.
var touched = new FileInfo("log.txt").LastWriteTime;
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.
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
What does it mean to 'flush to disk'?
it means that all downloaded status goes to flushing to disk,() the file stays there forever and doesnt write the file to hd...
Read more >Manually flushing write cache on Windows
On *nix systems, a user can use the sync command to force any pending writes in the kernel's disk cache to be flushed...
Read more >Flushing System-Buffered I/O Data to Disk - Win32 apps
Windows stores the data in file read and write operations in system-maintained data buffers to optimize disk performance.
Read more >Flush data to disk
Flush data to diskWriting a buffer to disk is called buffer flushing . Flush buffer-pool buffersFlushing of the buffers is triggered by specific...
Read more >Flush Cache to Disk
Performs an immediate flush of the FileMaker Pro internal file cache to the computer's hard disk.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:
FlushToDisk()
on bothFileSink
andRollingFileSink
PeriodicFlushToDisk
that calls the wrapped sink’sFlushToDisk()
method on a timer at some specified intervalTimeSpan? flushToDiskInterval
as an optional argument toWriteTo.File()
andWriteTo.RollingFile()
, and wrap the configured sink if it is specifiedSound like a plan?
@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 👍