void RecordMessage(CString prefix,int id,CString msg)
{
try
{
char filename[256];
sprintf(filename,"ReportLog\\%s-%s.txt",prefix,CTime::GetCurrentTime().Format("%Y年%m月%d日%H时")); //创建日志,名字+时间
char data[4096];
sprintf(data,"%s %s\r\n",CTime::GetCurrentTime().Format("%H:%M:%S"),msg);
int fh=_open(filename,_O_RDWR | _O_CREAT, _S_IREAD | _S_IWRITE);//打开文件,写入,关闭
_lseek(fh,0L,SEEK_END);
_write(fh, data, strlen(data));
_close(fh);
}
catch(CException*pe)
{
pe->Delete();
}
catch(...)
{
}
}
VC记录日志通用代码
最新推荐文章于 2019-11-06 16:31:37 发布