Log File: Watch your application's activities 

Submitted by date of submission user level 

Mahesh Chand 01/03/2000 Beginner 

Log files are used to write down an application's activity. They are basically text files. In this article, I will create a log file and show you how to call from an application which is performing some lengthy job.

Step 1: Create an instance of CStdioFile. 

CStdioFile file; 

Step 2: Create the file.

// Creating KC Convert log file

char* pFileName = "kcconvert.log";

CFileException e;

file.Open( pFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText|CFile::shareDenyNone, &e ) ; 

Step 3: Create a function which writes to the log file.

void CExportProgress::AddLog(CString szLog)

{

  // Write to the log file

  zLog += "\n";

  file.WriteString(szLog);

Step 4: Now call it from your application.

AddLog(" Application Date: Current Date,  Time: Current Time ");

if ( DoSomething == SUCCESS )

   AddLog(" Operation Succesful!");

else

   AddLog(" Operation Failed!"); 

 

Did you like this article? Please send your feedback to the Author. Your feedback helps us to improve the quality of our next article.

About the Author:

Mahesh is Admin and the founder of this site. He has been programming in VC++, Visual Basic, COM, ATL, Database Programming for 4 years. He can be reached at Mahesh. His  background includes Master's in Computer Science and Applications and Bachelor's in Mathematics and Physics. More...