文件读写–日志

 public static void WriteLog(string context)
        {
            using (StreamWriter w = File.AppendText("c:\\temp.txt"))
            {
                Log(context, w);
                w.Close();
            }


        }

        public static void Log(String logMessage, TextWriter w)
        {
            w.Write("\r\nLog Entry : ");
            w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
                DateTime.Now.ToLongDateString());
            w.WriteLine("  :");
            w.WriteLine("  :{0}", logMessage);
            w.WriteLine("-------------------------------");
            // Update the underlying file.
            w.Flush();
        }