Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TraceEvent function

The TraceEvent function sends an event to an event tracing session.

Syntax


ULONG TraceEvent(
  _In_  TRACEHANDLE SessionHandle,
  _In_  PEVENT_TRACE_HEADER EventTrace
);

Parameters

SessionHandle [in]

Handle to the event tracing session that records the event. The provider obtains the handle when it calls the GetTraceLoggerHandle function in its ControlCallback implementation.

EventTrace [in]

Pointer to an EVENT_TRACE_HEADER structure. Event-specific data is optionally appended to the structure. The largest event you can log is 64K. You must specify values for the following members of the EVENT_TRACE_HEADER structure.

  • Size
  • Guid or GuidPtr
  • Flags

Depending on the complexity of the information your provider provides, you should also consider specifying values for the following members.

  • Class.Type
  • Class.Level

Return value

If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is one of the system error codes. The following table includes some common errors and their causes.

Return codeDescription
ERROR_INVALID_FLAG_NUMBER

The Flags member of the EVENT_TRACE_HEADER structure is incorrect.

ERROR_INVALID_HANDLE

SessionHandle is not valid or specifies the NT Kernel Logger session handle.

ERROR_NOT_ENOUGH_MEMORY

The session ran out of free buffers to write to. This can occur during high event rates because the disk subsystem is overloaded or the number of buffers is too small. Rather than blocking until more buffers become available, TraceEvent discards the event.

Consider increasing the number and size of the buffers for the session, or reducing the number of events written or the size of the events.

Windows 2000:  Not supported.

ERROR_OUTOFMEMORY

The event is discarded because, although the buffer pool has not reached its maximum size, there is insufficient available memory to allocate an additional buffer and there is no buffer available to receive the event.

ERROR_INVALID_PARAMETER

One of the following is true:

  • SessionHandle is NULL.
  • EventTrace is NULL.
  • The Size member of the EVENT_TRACE_HEADER structure is incorrect.
ERROR_MORE_DATA

Data from a single event cannot span multiple buffers. A trace event is limited to the size of the event tracing session's buffer minus the size of the EVENT_TRACE_HEADER structure.

 

Remarks

Providers call this function.

Before the provider can call this function, the provider

  • Must call the RegisterTraceGuids function to register itself and the event trace class.
  • Must be enabled. A controller calls the EnableTrace function to enable a provider.

The event is either written to a log file, sent to event trace consumers in real time, or both. The LogFileMode member of the EVENT_TRACE_PROPERTIES structure passed to the StartTrace defines where the event is sent.

The trace events are written in the order in which they occur.

To trace a set of related events, use the TraceEventInstance function.

On Windows Vista, you should use the EventWrite function to log events.

Examples

For an example that uses TraceEvent, see Tracing Events.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Evntrace.h

Library

Advapi32.lib

DLL

Advapi32.dll

See also

EnableTrace
EVENT_TRACE_HEADER
RegisterTraceGuids
TraceEventInstance

 

 

Community Additions

Show:
© 2014 Microsoft. All rights reserved.