I got 2 possible solutions, which both aim at solving the issue on the per-file level rather then OS settings level.
If you wanted to change a Policy for Policies sake, then the Windows Policy Management maay have an option for this.
WriteThrough
Now there is a whole host of caches in play here - Application/Class, OS, the RAM in the Disk Eletronics. And I am unsure if it can affect the specific cache(s) you are worried about. But FileStream has a option called "WriteThrough":
Indicates that the system should write through any intermediate cache and go directly to disk.
https://learn.microsoft.com/en-us/dotnet/api/system.io.fileoptions
The Application/Class cache is trivial and to 99% disabeled by this.
The mention of "System" indicates to me that it will get to the OS cache (wich you seem worried about). But this is only a single line in the Documentation, so I can not say with certain it goes down to OS Level. But if there is one Option I would define for logging to a file and asume to be enabeled on all existing loggers, it this is it.
Asuming this is not for logging or similar streaming work and the core issue is the danger of corrupting file with partial writes, a minor redesign can fix that issue.
Writing to Tempfile -> Move
One surefire way to avoid corrupting a file when (re)writing it, is to write to a different temporary file - and then just swap those files out with a move (wich ideally will only change the File System Name entries). I did write some example code for this not to long ago after seeing this behavior in anything down to Word Processors:
string sourcepath; //containts the source file path, set by other code
string temppath; //containts the path of the tempfile. Should be in the same folder, and thus same partiion
//Open both Streams, can use a single using for this
//The supression of any Buffering on the output should be optional and will be detrimental to performance
using(var sourceStream = File.OpenRead(sourcepath),
outStream = File.Create(temppath, 0, FileOptions.WriteThrough )){
string line = "";
//itterte over the input
while((line = streamReader.ReadLine()) != null){
//do processing on line here
outStream.Write(line);
}
}
//replace the files. Pretty sure it will just overwrite without asking
File.Move(temppath, sourcepath);
The downside is of course you will temporarily need twice the Disk Space and it will cause a lot of extra write work on some modifications.