Skip to content

Flush-to-disk option #18

Closed
Closed
@temp-impl

Description

@temp-impl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions