question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flush-to-disk option

See original GitHub issue

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.

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:closed
  • Created 7 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
nblumhardtcommented, Oct 3, 2016

@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:

  1. Add FlushToDisk() on both FileSink and RollingFileSink
  2. Create a wrapper sink PeriodicFlushToDisk that calls the wrapped sink’s FlushToDisk() method on a timer at some specified interval
  3. Add TimeSpan? flushToDiskInterval as an optional argument to WriteTo.File() and WriteTo.RollingFile(), and wrap the configured sink if it is specified

Sound like a plan?

1reaction
nblumhardtcommented, Oct 7, 2016

@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 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found