void OutputLog(LPCTSTR logName, CString msg)
{
try
{
//设置文件的打开参数
CStdioFile outFile(logName, CFile::modeNoTruncate | CFile::modeCreate | CFile::modeWrite | CFile::typeText);
CString msLine;
CTime tt = CTime::GetCurrentTime(); // 获取当前时间
//作为Log文件,经常要给每条Log打时间戳
msLine = tt.Format("[%Y-%m-%d, %H:%M:%S] ") + msg;
msLine += "\n";
//在文件末尾插入新纪录
outFile.SeekToEnd();
outFile.WriteString(msLine);
outFile.Close();
}
catch (CFileException *fx)
{
fx->Delete();
}
}
网友评论