C#为txt文件追加文字并换行

string path= System.Windows.Forms.Application.StartupPath + "\\ErrorLog\\"+fileName +".txt";

if (!File.Exists(path))

{

FileInfo myfile = new FileInfo(path);

FileStream fs = myfile.Create();

fs.Close();

}

StreamWriter sw = File.AppendText(path);

sw.WriteLine(errorMsg);

sw.Flush();

sw.Close();