1. Background
Recently, I develop a software, which can log data into a txt file. But finding that this software will crash after long time test about 2 days. After analysing and debugging, find the root reason is that software can’t open the log file immediately under this log rate. Because the log file become very big after long time logging.
2. Limit log file size
When implementing log function, should consider limit the log file size. The flow chart diagram is show as below.
Getting file size can use the following code:
CFileStatus fStatus;
long lFileSize;
CFile::GetStatus("FilePath+FileName", fStatus);
lFileSize=fStatus.m_size;