写入临时日志到文本

       private void ToOrderExceptionLog(string strMsg)
        {
            String saveUri ="D:\\调试日志";
            if (Directory.Exists(saveUri))
            {
                String saveFileName = @saveUri + "\\" + DateTime.Now.ToLongDateString() + ".txt ";
                FileInfo nfile = new FileInfo(saveFileName);
                if (!nfile.Exists) { FileStream crtorchage = System.IO.File.Create(saveFileName); crtorchage.Flush(); crtorchage.Close(); }
                StreamWriter wt = new StreamWriter(saveFileName, true);//以可以追加文本的方式打开nfile流  
                wt.WriteLine(strMsg); wt.Flush(); wt.Close();
            }
            else
            {
                Directory.CreateDirectory(saveUri);
                String saveFileName = @saveUri + "\\" + DateTime.Now.ToLongDateString() + ".txt ";
                FileStream crtorchage = System.IO.File.Create(saveFileName);
                crtorchage.Flush(); crtorchage.Close();
                StreamWriter wt = new StreamWriter(saveFileName);//不可追加文本  
                wt.WriteLine(strMsg); wt.Flush(); wt.Close();
            }
        }

 

posted @ 2014-01-21 17:38  ``炯``  阅读(205)  评论(0编辑  收藏  举报