LlmEnableTrace Function  
 
BOOL WINAPI LlmEnableTrace(
  LPCTSTR lpszTraceFile,  
  DWORD dwTraceFlags  
);

The LlmEnableTrace function enables the logging of network function calls to a file.

Parameters

lpszTraceFile
A null-terminated string which specifies the name of the logfile which will be appended to or created. It is recommended that this file always specify an absolute path to avoid any ambiguity. The path can contain environment variable names surrounded by percent (%) symbols which will be expanded prior to opening or creating the file. If the file already exists, the current process must have read and write permission to access the file.
dwTraceFlags
An unsigned integer that specifies one or more options. This parameter is constructed by using a bitwise operator with any of the following values:
Value Description
TRACE_INFO All function calls are logged, but without detailed information about the data being transmitted. This is the most basic level of logging and can be useful when debugging call sequences or return values without the additional overhead of logging the data being exchanged between the client and server.
TRACE_ERROR Only those function calls which fail are written to the file. It is important to note that this only relates to errors at the networking level and not errors which can occur at the protocol level, such as an error response from the server because the client sends an invalid request.
TRACE_WARNING Only those function calls which fail or return values which indicate a warning are written to the file. Warnings consist of error conditions which do not normally constitute a failure at the network level. The most common warning that can occur is a timeout while waiting for a response from the remote host.
TRACE_HEXDUMP In addition to logging function calls, this option writes the raw data that is sent and received over the network, shown in both hexadecimal and ASCII formats. This is especially useful for debugging protocol-level issues and verifying payload contents and responses.
TRACE_TRUNCATE If the file already exists and is not read-only, the contents will be deleted before logging begins. This option is typically used to begin a new log file each time tracing is enabled, rather than appending to an existing file. This option requires the process to have permission to read, write and delete the file in the specified folder.
TRACE_PROCESS All function calls in the current process are logged, rather than only those functions in the current thread. This option is useful for multithreaded applications that are using worker threads.

Return Value

If the function succeeds, the return value is non-zero. A return value of zero indicates an error, typically because the file could not be opened or created by the current process.

Remarks

Logging is enabled and disabled at the thread or process level, depending on the flags passed to this function, and is not associated with a specific client session. When logging is enabled, the information is appended to the specified file. If the file does not exist, it will be created. To limit the size of the file, enable and disable logging only around those sections of code that you wish to debug. If you do not provide a full path to the file, it will be relative to the current working directory for the process. This can produce unexpected results in multithreaded applications because the current directory is global to the entire process and can be changed by any thread at any time.

If logging is not enabled, there is no negative impact on performance or throughput. Once enabled, application performance can degrade, especially in those situations in which there is a large amount of data being exchanged. The log file can contain detailed information about connection attempts and authentication requests, potentially exposing user credentials, authorization tokens and API keys. If you enable logging in a production release of your application, this information can also potentially reveal file structures, API endpoints and data specific to your application. Exercise caution when preserving or sharing the contents of the file.

The TRACE_HEXDUMP option can generate very large files because it includes all of the data exchanged between your application and the remote host. The TRACE_TRUNCATE option is only evaluated when logging is first enabled for a thread or process. If logging is already active, specifying this option will have no effect.

The log file has the following format:

APPNAME 105020 0000 INF: WSAAsyncSelect(46, 0xcc4, 0x7e9,0x27) returned 0
APPNAME 105020 0015 WRN: connect(46, 192.0.0.1:1234, 16) returned -1 [10035]
APPNAME 111535 0000 ERR: accept(46, NULL, 0x0) returned -1 [10038]

The first column contains the name of the process. The second column is the local time in hours, minutes and seconds. The third column is the elapsed time in milliseconds since the previous function call. The fourth column identifies if the logged event contains information, a warning, or an error. What follows is the name of the network function being called, the arguments passed to the function and the function's return value. If a warning or error is reported, the error code is appended to the record and the value is enclosed in brackets.

If function parameters are passed as integer values, they are recorded in decimal. If the parameter or return value is a memory address, it is recorded as a hexadecimal value preceded with "0x". Those functions which expect network addresses are displayed in one of two formats:

aa.bb.cc.dd:nnnn
[xxxx:xxxx:xxxxx:xxxx::xxxx]:nnnn

With an IPv4 address, the first four numbers separated by periods represent the IP address, and the number following the colon represents the port number in host byte order. If an IPv6 address is used instead of IPv4, the address will be a series of hexadecimal digits separated by colons and enclosed in brackets. In the second line of the above example, a connection is being made to a system with the IPv4 address 192.0.0.1 on port 1234.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmDisableTrace