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

net 日志

Posted on 2010-06-11 12:04  gzlxm  阅读(174)  评论(0)    收藏  举报

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();
                }
            }