c# 写入文件

 if (!File.Exists(path))
                {
                    File.Create(path).Close();
                }
                using (StreamWriter w = File.AppendText(path))
                {
                    w.WriteLine("Error log:");
                    w.WriteLine("Error Time:"+DateTime.Now);
                    w.WriteLine("Error TargetSite:" + error.TargetSite);
                    w.WriteLine("Error Message:" + error.Message);
                    w.WriteLine("Error StackTrace" + error.StackTrace);
                    w.WriteLine("-----------------------------------------------------------------------------------------------------------------------");
                    w.Flush();
                    w.Close();
                }

 

posted @ 2013-05-13 16:11  louiskoo  阅读(196)  评论(0编辑  收藏  举报