::GetTickCount() C++运行时刻
System.Environment.TickCount; C#运行时刻
C++
CFile file;
CString strLog;
strLog.Empty();
file.Open("C:\\Xf4100.log", CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate);
file.SeekToEnd();
file.Write(strLog, strLog.GetLength());
file.Close();
C#
public static void LogOut(string strLogTxt1, string strLogTxt2 = "", string strLogExe = "", string strFileName = "")
{
string strFilePath = System.Environment.CurrentDirectory;
System.Text.StringBuilder strLog = new System.Text.StringBuilder();
strLog.Append(DateTime.Now.ToString(@"yyyy-MM-dd hh:mm:ss fff "));
if (!string.IsNullOrEmpty(strLogExe))
{
strLog.Append(DateTime.Now.ToString(strLogExe + @" "));
}
strLog.Append(strLogTxt1);
if (!string.IsNullOrEmpty(strLogTxt2))
{
strLog.Append(@" " + strLogTxt2);
}
if (string.IsNullOrEmpty(strFileName))
{
strFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName + DateTime.Now.ToString("_MMdd") + @".log";
}
else
{
strFileName += @".log"; ;
}
strFilePath += @"\" + strFileName;
var fileStm = new System.IO.FileStream(strFilePath, System.IO.FileMode.Append, System.IO.FileAccess.Write);
var stmWiteer = new System.IO.StreamWriter(fileStm);
stmWiteer.WriteLine(strLog);
stmWiteer.Close();
}