How to incorporate logging to an application

28 01 2012

Once we deploy an application into the client machines and somehow if they face any crash or defects, generally we will be in trouble! Right? 😦

On such situations its our responsibility to fix it ASAP. So we should have good debugging skills to locate the issue and fix it at the earliest. There are different methods to improve debugging and better error tacking. One among them is logging.  Logging in the context of any application means recording what the application is doing. This post is about to incorporate logging mechanism to your application.

Generally programmers spend a high percentage of the time debugging to locate defect rather than writing code. So if we incorporate a logging mechanism in our applications, it will generate an error (log) file at a client and we can take the logg file and see where the error appeared, maybe even the error, or at least until where the application went ok… 🙂

We can inlude a CLogger class to our application to establish this and it is better to design this as a Singleton class. Please see the attached files to get it clear.




void Main()
	if (!CLogger::Instance()->OpenLogFile())
		AfxMessageBox(_T("Loggin failed!"));

	CLogger::Instance()->LogMessage("\r\nTestFun1 successfully executed");

	CLogger::Instance()->LogMessage("\r\nTestFun2 successfully executed");

	CLogger::Instance()->LogMessage("\r\nTestFun3 successfully executed");


Don’t include to much logging statememts, means that sould not affect the performance of your application. Keep only valid data in the looging. Otherwise it will be a overhead for your application.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: