美文网首页MFC
mfc 记录 log

mfc 记录 log

作者: 云胡同学 | 来源:发表于2019-08-20 16:43 被阅读0次
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();
    }
}

相关文章

网友评论

    本文标题:mfc 记录 log

    本文链接:https://www.haomeiwen.com/subject/migpsctx.html