gate_s

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 public void CheckLog(string Log)
      {
             if (File.Exists(LogFile))
              {
                    WriteLog(Log);
               }

               else
                {
                    CreateLog();
                    WriteLog(Log);
               }
            }

         private void CreateLog()
           {
                StreamWriter SW;
                SW = File.CreateText(LogFile);
                SW.WriteLine("Log created at: " +
                                     DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss"));
                SW.Close();
           }

           private void WriteLog(string Log)
           {
                using (StreamWriter SW = File.AppendText(LogFile))
                {
                    SW.WriteLine(Log);
                    SW.Close();
                }
           }

posted on 2014-02-14 09:49  gate_s  阅读(640)  评论(0编辑  收藏  举报