Posted By

jwwest on 01/19/11


Tagged

debugging logging


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

cybermax
thastyle


Log message to file


 / Published in: C#
 

  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  

You need to login to post a comment.