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