- 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
- {
- sw.Close();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1004201512177.html
来源: http://www.codesnippet.cn/detail/1004201512177.html