Thursday, 7 May 2015

C# Append lines to a file using a StreamWriter


StringBuilder strBuilLog = new StringBuilder();
string strLogData = "Welcome to log data \t";
strBuilLog.Append(strLogData);
string strLogData2 = "Welcome to log data 2" + Environment.NewLine;
strBuilLog.Append(strLogData2);
string strLogDataFinal = "Welcome to log data final \t";
strBuilLog.Append(strLogDataFinal);
using (StreamWriter strwLog = new StreamWriter("c:\\log.txt"))
{
strwLog.Write(strBuilLog.ToString());
strwLog.Close();
}
view raw gistfile1.cs hosted with ❤ by GitHub