C# 文件操作(一)

1、说明:

写入文件内容,如果文件中有内容,则进行追加,目录是程序集下的目录

复制代码

public static void WriteLog(string value)
{

  try
  {

    //目录是程序集下的Debug目录
    string strPath = AppDomain.CurrentDomain.BaseDirectory + "\\Error.txt";
    StreamWriter sw = new StreamWriter(strPath, true);
    sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " : " + value);
    sw.Close();
    sw.Dispose();
  }
  catch (Exception ex)
  {
    throw new Exception(ex.Message);
  }

}

复制代码
posted @   順萁洎嘫  阅读(167)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示