How to create log file and how it use?
-
Hi All I am developing project in VC++ 6.0 and I want to use log file in my application, so this file to be create and how it use in project. Thnaks Atool Atool
Hi You can use the function below which opens a log.txt in your exe's local folder and writes whatever message you pass thro it . Its also threadsafe . If your application is single threaded then remove CSingleLock stuff ... if flag is 0 then 'msg' is written to log only and not printed in console . If you want to do both - then pass flag =1... int WriteMessage(CString msg,UINT flag){ int ret=0; CSingleLock sLock(&sec);// remove this if your app is single threaded.. sLock.Lock();//remove this if your app is single threaded.. TRY { ret=logfile.Open("log.txt",CStdioFile::modeWrite );// try opening log.txt if(ret==1)// if succeeded { logfile.SeekToEnd();//go to end of log file CTime t = CTime::GetCurrentTime();// time stamp stuff CString tim=t.Format("%m/%d/%Y %H:%M:%S : "); tim=tim+msg+"\n"; logfile.WriteString(tim);//write to log with the message passed thro "msg" logfile.Close();//close the file if(flag) { cout<m_cause << "\n"; #endif } END_CATCH sLock.Unlock();//remove this if your app is single threaded.. return ret; }
redindian
-
Hi All I am developing project in VC++ 6.0 and I want to use log file in my application, so this file to be create and how it use in project. Thnaks Atool Atool
-
Hi You can use the function below which opens a log.txt in your exe's local folder and writes whatever message you pass thro it . Its also threadsafe . If your application is single threaded then remove CSingleLock stuff ... if flag is 0 then 'msg' is written to log only and not printed in console . If you want to do both - then pass flag =1... int WriteMessage(CString msg,UINT flag){ int ret=0; CSingleLock sLock(&sec);// remove this if your app is single threaded.. sLock.Lock();//remove this if your app is single threaded.. TRY { ret=logfile.Open("log.txt",CStdioFile::modeWrite );// try opening log.txt if(ret==1)// if succeeded { logfile.SeekToEnd();//go to end of log file CTime t = CTime::GetCurrentTime();// time stamp stuff CString tim=t.Format("%m/%d/%Y %H:%M:%S : "); tim=tim+msg+"\n"; logfile.WriteString(tim);//write to log with the message passed thro "msg" logfile.Close();//close the file if(flag) { cout<m_cause << "\n"; #endif } END_CATCH sLock.Unlock();//remove this if your app is single threaded.. return ret; }
redindian
-
Hi All I am developing project in VC++ 6.0 and I want to use log file in my application, so this file to be create and how it use in project. Thnaks Atool Atool
These should at least get you started: http://www.codeproject.com/file/fixed-length_logging.asp[^] http://www.codeproject.com/debug/logtrace.asp[^] http://www.codeproject.com/ce/GenericLogFunctionality.asp[^]
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi All I am developing project in VC++ 6.0 and I want to use log file in my application, so this file to be create and how it use in project. Thnaks Atool Atool