Created
October 16, 2018 14:34
-
-
Save jrocha/1fd533ae51bbe9e91278747e1b304dc6 to your computer and use it in GitHub Desktop.
Flush file without closing it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp { | |
class Program { | |
static void Main(string[] args) { | |
using (var sw = new StreamWriter(File.Open("log.txt", FileMode.Append, FileAccess.Write, FileShare.Read))) { | |
string cmd = null; | |
while (cmd != "q") { | |
sw.WriteLine(DateTime.Now.ToLongTimeString()); | |
sw.Flush(); | |
cmd = Console.ReadLine(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment