Log message to file


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public void LogMessageToFile(string msg)
  2. {
  3. System.IO.StreamWriter sw = System.IO.File.AppendText("log.txt");
  4. try
  5. {
  6. string logLine = System.String.Format(
  7. "{0:G}: {1}.", System.DateTime.Now, msg);
  8. sw.WriteLine(logLine);
  9. }
  10. finally
  11. {
  12. sw.Close();
  13. }
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.