← back to articles

❯ cat log-message-to-a-file.md

Log Message to a file

1 min readtr#C##Log
LogMessageToFile ("Mesaj Log durumu"); 
 
using System; 
using System.IO; 
 
public string GetTempPath()
{
   string path = 
      System.Environment.GetEnvironmentVariable ("TEMP");
   if (!path.EndsWith ("\"))
   {
      path += "\";
   }
   return path;
}
 
public void LogMessageToFile (string message)
{
   System.IO.StreamWriter sw = 
      System.IO.File.AppendText(
         GetTempPath() + "Logfile.txt"); // Dosya adının değişikliği
   try
   {
      string logLine = 
         System.String.Format(
            "{0:G}: {1}.", System.DateTime.Now, message);
      sw.WriteLine(logLine);
   }
   finally
   {
      sw.Close();
   }
}