简体   繁体   中英

Log file creation in MFC (VC++)?

I want to create a Log file in MFC that should write to log file everytime it should append the logging details , it should not overrite the exisiting details.And there should be some size limit like if after this much size a new file should create.

How to achieve this? any help is appreciated. Thanks.

Look at the CStdioFile Class, specifically the method CStdioFile::WriteString . It makes it easy to write text to a file.

When you open the file you want to combine the CFile::modeCreate and CFile::modeNoTruncate flags to create the file only if it doesn't exist already.

You can get the size of the file using the CFile::GetLength method.

嗨,我不知道您可以使用外部库,但log4cpp很好的库,您不需要编写自己的logger类链接文本实现

Aside from CStdioFile, I also use WritePrivateProfileString with the date and time as key name. You can thus add log strings in this form:

[LOG]
5-2-2010 15:06:10:804=Starting program...
5-2-2010 15:04:53:815=Data updated succesfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM