Have C# WPF application that continuously appends to various log files.
Ran into trouble when customer's backup program was interfering with access to the log files.
Apparently, Windows SMB layer was often causing ten seconds or more delay for file open, then failing because backup program had opened the file with exclusive access.
Modified C# application to keep logs open, in FileMode.Append, FileAccess.Write and FileShare.Read.
After appending to log, I tried calling StreamWriter.Flush but files were zero length and unreadable by other processes.
I then tried calling StreamWriter.FlushAsync, and now files are non-zero length, are readable by other processes, but flush is of course happening asynchronously and my own process can throw an exception if it attempts to again append to a log that is still flushing asynchronously.
How to wait for StreamWriter.FlushAsync to complete?