1,CStdioFile类建立日志文件,定义全局变量,每个需要记录位置的地方,以当前时间作为文件名称;
在C**App类的初始化函数 InitInstance() 建立日志文件,日志文件路径是当前目录下建立Log文件夹
//log text 全局变量
CStdioFile g_logFile;
//日志文件
CString filename;
CTime tm = CTime::GetCurrentTime();
filename = tm.Format(L"%Y%m%d_%H%M%S.txt");
char pCurPath[100];
GetCurrentDirectoryA( 100, pCurPath );
filename = CString(pCurPath) + L"\\Log\\" + filename;
g_logFile.Open( filename,CFile::modeCreate|CFile::modeWrite );
2,CStdioFile 默认情况下不能打印汉字,需要添加一行代码
//非常关键,允许打印汉字
setlocale(LC_CTYPE,"chs");
CString strLog;
CTime tm = CTime::GetCurrentTime();
strLog = tm.Format(L"\n\n%Y\\%m\\%d %H:%M:%S");
g_logFile.WriteString( strLog );
g_logFile.WriteString(L"\n程序启动!");