using System;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace BaseLibRWFile
{
public class Log
{
public object objLock = new object();
///
/// 保存log
///
/// 文件路径
/// 文件名称
/// 写入内容
///
public bool SaveTxt(string strFilePath, string strFileName, string strMsg)
{
lock(objLock)
{
try
{
strMsg = DateTime.Now.ToString("HH:mm:ss:fff") + "---" + strMsg + "\r\n";
FileOperate.Directory_Create(strFilePath);
string strPath = strFilePath + "\\" + strFileName;
if (!File.Exists(strPath))
{
using (FileStream fs = new FileStream(strPath, FileMode.CreateNew))
fs.Close();
}
using (FileStream fsw = new FileStream(strPath, FileMode.Append))
{
byte[] mSG_data = Encoding.UTF8.GetBytes(strMsg);
fsw.Write(mSG_data, 0, mSG_data.Length);
fsw.Close();
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "保存text文件出错\r\nSave text error");
return false;
}
}
}
}
}