#region 記錄文本文件日志方法 /// <summary>
/// 記錄文本文件日志方法
/// </summary>
/// <param name="FileContent">需要記錄的文件內容</param>
/// <param name="TxtFileName">保存的文件名</param>
/// <param name="ErrMsg">錯誤信息</param>
/// <returns></returns>
public static bool WriteFile(string FileContent, string TxtFileName, out string ErrMsg)
{
ErrMsg = string.Empty;
StreamWriter writer = null;
string sCurDate = System.DateTime.Now.ToString("yyyy-MM-dd");
string sFile = sCurDate + TxtFileName + ".txt";
sFile = "D:\\Log\\Log001.txt";
try
{
if (File.Exists(sFile))
writer = new StreamWriter(sFile, true, System.Text.Encoding.GetEncoding("UTF-8"));
else
writer = new StreamWriter(sFile, false, System.Text.Encoding.GetEncoding("UTF-8"));
string sDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss");
writer.WriteLine("<" + sDateTime + "> " + " " + FileContent);
}
catch (IOException e)
{
ErrMsg = e.Message;
return false;
}
finally
{
if (writer != null)
writer.Close();
}
return true;
}
#endregion