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 @ 2015-08-11 13:55  順萁洎嘫  阅读(162)  评论(0编辑  收藏  举报