C++ 输出日志
//增加日志 void CUniversalCabinetStateDlg::WriteOperateTxt(CString strLog) { //m_csWriteLog.Lock(); CTime time = CTime::GetCurrentTime(); CString strLogPath = "D:\\TmkMvSys64_LD\\Log\\UCContnrolerLog"; CString strLogPathTxt = ""; //判断目录是否存在,不存在则创建 if (!DirectoryExist(strLogPath)) { //目录不存在,则创建 目录 CreateDirectoryFile(strLogPath); } strLogPathTxt.Format("%s\\%4d-%2d-%2d-%2d.log",strLogPath,time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour()); CString strtime = ""; strtime.Format(_T("%4d-%2d-%2d-%2d:%2d:%2d\t"),time.GetYear(),time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()); strLog = strtime + strLog; #if 1 FILE* wFileTxt = fopen(strLogPathTxt, "at+"); if(NULL != wFileTxt) { fprintf(wFileTxt,"%s\n",strLog); fclose(wFileTxt); } #else CFile wFileTxt(strLogPathTxt,CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite); wFileTxt.Write(strLog.GetBuffer(strLog.GetLength()),strLog.GetLength()); //fprintf(wFileTxt,"%s\n",strLog); wFileTxt.Close(); //fclose(wFileTxt); #endif //m_csWriteLog.Unlock(); }