本文实例讲述了C#记录消息到日志文件的方法。分享给大家供大家参考。具体实现方法如下: public void LogMessageToFile(string msg) { System.IO.StreamWriter sw = System.IO.File.AppendText(log.txt); try { string logLine = System.String.Format({0:G}: {1}., System.DateTime.Now, msg); sw.WriteLine(logLine); } finally { s