I have a C# .NET 3.5 Windows Form program with this method:
private void toLog(string sLog)
{
richTextBox1.Text += DateTime.Now.ToString("T") + ": " + sLog + "\n";
richTextBox1.Update();
richTextBox1.Refresh();
using (StreamWriter writer = new StreamWriter("log.txt", true))
{
writer.WriteLine(DateTime.Now.ToString("T") + ": " + sLog);
writer.Flush();
writer.Dispose();
}
}
The idea is that I can submit log entries with it and it will write the entry to both the richtextbox and the log file.
Here’s the thing… the streamwriter only writes the first time the method is called! The richtextbox updates great. Flush() and Dispose() were something I tried later out of desperation, but I guess the using block should handle that.
Any ideas? Thanks!
I think problem could be in
StreamWriter("log.txt",: path could be changed inside your app, so you’d better to use full path here.Example: