在执行一些批量操作时,想记录一些执行日志信息,越简单方便越好啊。
提供一个常用的简单方法,将信息记录在txt文件里:

public static void log(string content, string path)
        {
            string strFileName = path;
            //判断是否存在
            if (File.Exists(strFileName))
            {
                //存在
                StreamWriter wlog;
                wlog = File.AppendText(strFileName);
                wlog.Write("\r\n{0}", content);
                wlog.Flush();
                wlog.Close();
            }
            else
            {
                //不存在
                FileStream fs1 = new FileStream(strFileName, FileMode.Create, FileAccess.Write);//创建写入文件 
                StreamWriter sw = new StreamWriter(fs1);
                sw.WriteLine(content);//开始写入值
                sw.Close();
                fs1.Close();

            }

        }

 

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-21
  • 2021-12-13
  • 2021-07-06
  • 2021-11-25
  • 2021-08-02
相关资源
相似解决方案