liuruitao
  /// <summary>
        /// 创建并写日志
        /// </summary>
        /// <param name="SuccessA100"></param>
        /// <param name="Result"></param>
        public void WriteLog(List<string> SuccessA100,string Result,string A102)
        {
            if (SuccessA100 == null)
            {
                return;
            }
            string txtPath = AppDomain.CurrentDomain.BaseDirectory + "log\\" +A102 + "\\"+ Result +A102.Replace("-", "")+DateTime.Now.ToString("yyyyyMMdd")  + ".csv";

            if (!File.Exists(txtPath))
            {
                if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102 ))
                {
                    Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102);
                }

                FileStream fs1 = new FileStream(txtPath, FileMode.Create, FileAccess.Write);//创建写入文件 
                using (StreamWriter sw = new StreamWriter(fs1))
                {
                    sw.WriteLine("A001,");
                    foreach (string a100 in SuccessA100)
                    {
                        sw.WriteLine(a100+",");//开始写入值
                    }
                    sw.Close();
                    fs1.Close();
                }
            }
            else
            {
                FileStream fs = new FileStream(txtPath, FileMode.Append, FileAccess.Write);
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (string a100 in SuccessA100)
                    {
                        sw.WriteLine(a100 + ",");//开始写入值
                    }
                    sw.Close();
                    fs.Close();
                }

            }
            Thread.Sleep(1000);
        }

 

分类:

技术点:

相关文章:

  • 2022-01-27
  • 2021-12-19
  • 2022-02-25
  • 2021-11-23
  • 2021-10-03
  • 2022-01-04
  • 2021-10-07
猜你喜欢
  • 2021-09-21
  • 2021-11-23
  • 2021-07-29
  • 2021-11-01
  • 2021-12-03
相关资源
相似解决方案