LogTrace - A DLL to log trace output to a file | CodeGuru

LogTrace – A DLL to log trace output to a file

Environment: MSVC 5.0 The code was designed to build a dll to log trace statements to a text file at customer sites. At the end of the day the customers emails me the text log. To use the LogTrace.dll in your project add LogTrace.lib to the Object/Library modules in your linker settings and include the […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 11, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: MSVC 5.0

The code was designed to build a dll to log trace statements to a text file
at customer sites. At the end of the day the customers emails me the text log.
To use the LogTrace.dll in your project add LogTrace.lib to the Object/Library modules in your linker settings
and include the header Trace.h to your project.

In your InitInstance() call

	TraceStart();

or

	TraceReadINI();

After that you can call Trace() like printf or TRACE

	Trace(“This is my string value [%s]n”, m_strMessage);  //Works like printf or TRACE

Exported functions

TraceStart(char *pszPathName = NULL) A call to TraceStart() will start tracing
until end of execution or TraceStop(). The log will default to the directory of the application
that called it. You can over ride the default behavior by passing in your own path, file name and
file name extension. The existing log is always numerically archived. If more than one
instance of an application is executing, then susequent applications will have the post fix
‘HMODULE’ in the log entries.
TraceReadINI() Reads control values from the applications ini file.

[TRACE]
;Specific log name and path
PathAndFileName=C:A_TESTmylog.txt
;1: file will be flushed after every Trace(), 0: no flushing
FLUSH=0

If you use TraceReadINI then you do not have to use TraceStart.

Trace(const char *pszFormat, …) Works just like TRACE() or printf(). The first parameter can be any length,
the sum of the additional parameters is limited to 1024 characters.
TraceSuspend(bool bTrueToSuspend) When true logging is suspended until set back to false.
Default is false
TraceStop() The current log is closed. To continue logging, explicitly call TraceStart().
In the event of multiple programs writing to the same log, the log will not be closed. The next
call to TraceStart() will append to the existing log.
TraceClockCapture(char* pszComment = NULL) Captures the current clock value.
TraceClockDuration (char* pszComment = NULL) Writes the number of seconds passed since the last TraceClockCapture().
TraceFlush(bool bForceFlush) You can turn it off to increase performance, but if the
application fails you may not get the last several dozen statements logged written to the
log file.
Default is true.
TraceWithTime(bool bValue) Causes the Trace() statement to output the time of each
trace statement. The year value is not output.
Default is true.

Download source – 10KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.