Platform SDK: Performance Monitoring

PdhOpenLog

The PdhOpenLog function opens the specified log file for reading or writing.

PDH_STATUS PdhOpenLog(
  LPCTSTR szLogFileName, 
  DWORD dwAccessFlags,   
  LPDWORD lpdwLogType,   
  HQUERY hQuery,         
  DWORD dwMaxSize,       
  LPCTSTR szUserCaption, 
  HLOG *phLog            
);

Parameters

szLogFileName
[in] A pointer to a null-terminated string containing the name of the buffer that contains the name of the log file to be opened.
dwAccessFlags
[in] The type of access to be specified when the log file is opened. This parameter can be one of the following values.
Value Meaning
PDH_LOG_READ_ACCESS A new log file is opened for a read operation.
PDH_LOG_WRITE_ACCESS A new log file is opened for a write operation.
PDH_LOG_UPDATE_ACCESS An existing log file is opened for a write operation.

The value selected from the previous table can be combined using the OR operator with one of the following create access flags.
Value Meaning
PDH_LOG_CREATE_NEW A new log file with the specified name is created.
PDH_LOG_CREATE_ALWAYS A new log file with the specified name is created and any existing log file with the same name is erased.
PDH_LOG_OPEN_EXISTING An existing log file with the specified name is opened. If a log file with the specified name does not exist, this is equal to PDH_LOG_CREATE_NEW.
PDH_LOG_OPEN_ALWAYS An existing log file with the specified name is opened or a new log file with the specified name is created.

lpdwLogType
[in] A pointer to a DWORD that indicates the type of log file to be opened. This parameter can be one of the following values.
Value Meaning
PDH_LOG_TYPE_UNDEFINED Undefined log file format.
PDH_LOG_TYPE_CSV Text files containing column headers in the first line, and individual data samples in each subsequent line.
PDH_LOG_TYPE_TSV Same as PDH_LOG_TYPE_CSV.
PDH_LOG_TYPE_BINARY Binary log file format. Includes circular log files.
PDH_LOG_TYPE_PERFMON Perfmon log file format.

hQuery
[in] A buffer containing the query handle. The value can be NULL if the log file is to be opened for reading.
dwMaxSize
[in] The maximum size of the log file, if the log file is a limited-size or circular log file.
szUserCaption
[in] A pointer to a null-terminated string containing the name of the buffer that contains the user-defined caption of the log file. A log file caption generally describes the contents of the log file. When an existing log file is opened, the value of this parameter is ignored.
phLog
[out] A pointer to a buffer that receives a handle to the opened log file.

Return Values

If the function succeeds, it returns ERROR_SUCCESS.

If the function fails, the return value is a PDH error status defined in PDHMsg.h. The following are possible error values.

Error value Description
PDH_INVALID_ARGUMENT An argument is not correct or is incorrectly formatted.

Remarks

When using this function to write performance data to a log file, a query must first be opened using PdhOpenQuery.

There must be a currently opened query, and the desired counters must be added to it, before this function is called.

Note that log files in the Perfmon format can only be opened for reading.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows 2000.

See Also

PdhOpenQuery, PdhUpdateLog, PdhUpdateLogFileCatalog,PdhGetLogFileSize