2012年1月18日 星期三

[.Net] A sample function for write log in file.

Just record how to write string into text file.


        protected void writeLog(string strLog)
        {
   string filePath = @"\Storage Card\log.txt";   // You could replace the file path.


            // Create or open file.
            FileStream fsOut = new FileStream(filePath, FileMode.Append);
            StreamWriter sw = new StreamWriter(fsOut, Encoding.Default);


            // Write log.
            sw.WriteLine(strLog);
            sw.Flush();


            // Close file.
            sw.Close();
            fsOut.Close();
        }