Skip to content

Instantly share code, notes, and snippets.

@jrocha
Created October 16, 2018 14:34
Show Gist options
  • Save jrocha/1fd533ae51bbe9e91278747e1b304dc6 to your computer and use it in GitHub Desktop.
Save jrocha/1fd533ae51bbe9e91278747e1b304dc6 to your computer and use it in GitHub Desktop.
Flush file without closing it
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