Post · 13 min read· pp. 544–552

LogFileMode

SKETCH OF HOW RESEARCH MIGHT CONTINUE AND RESULTS BE PRESENTED

The key to the many options for configuring a tracing session, known informally as a logger, is a set of bit flags that are typically experienced in user mode as the LogFileMode member of an EVENT_TRACE_PROPERTIES structure. Among the options is that a tracing session may have its buffers in user-mode memory, but if these are not specified, the tracing session is the kernel’s to start and manage. For communication to the kernel, nowadays through the NtTraceControl function, the session’s properties are repackaged as a WMI_LOGGER_INFORMATION structure, still with the bit flags as a ULONG member named LogFileMode. This also is how the kernel presents the properties to itself for those sessions that it starts from AutoLogger settings in the registry. This note is concerned solely with this kernel-mode interpretation of the LogFileMode in the WMI_LOGGER_INFORMATION and the eventual retention of this LogFileMode as the LoggerMode in the WMI_LOGGER_CONTEXT.

Most of the log file modes are documented by Microsoft as Logging Mode Constants and are defined as macros in EVNTRACE.H. Not all were documented immediately. For a few, Microsoft’s names are known only from the NTWMI.H header which Microsoft published in the Enterprise edition of the Windows Driver Kit (WDK) for Windows 10 version 1511.

In the following list of log file modes, the versions are those for which the flag is known to have some explicit recognition by the kernel, even if only to reject it as invalid. Where versions are not shown, the flag is not known to the kernel but may instead be vital to the separate NTDLL implementation that lets user-mode processes do their own event tracing.

ValueNameVersionsRemarks
0x00000001EVENT_TRACE_FILE_MODE_SEQUENTIAL5.0 and higherdefined in DDK for Windows 2000; documented by January 2001
0x00000002EVENT_TRACE_FILE_MODE_CIRCULAR5.0 and higherdefined in DDK for Windows 2000; documented by January 2001
0x00000004EVENT_TRACE_FILE_MODE_APPEND5.1 and higherdefined in DDK for Windows XP; documented by January 2001
0x00000008EVENT_TRACE_FILE_MODE_NEWFILE5.1 and higherdefined in DDK for Windows XP; documented by January 2003
0x00000010EVENT_TRACE_USE_MS_FLUSH_TIMER6.1 and higherdefined in Enterprise WDK for 1511
0x00000020EVENT_TRACE_FILE_MODE_PREALLOCATE6.0 and higherdefined in DDK for Windows XP; documented by January 2003
0x00000040EVENT_TRACE_NONSTOPPABLE_MODE6.0 and higherdefined in WDK for Windows Vista
0x00000080EVENT_TRACE_SECURE_MODE6.0 and higherdefined in WDK for Windows Vista
0x00000100EVENT_TRACE_REAL_TIME_MODE5.0 and higherdefined in DDK for Windows 2000; documented by January 2001
0x00000200EVENT_TRACE_DELAY_OPEN_FILE_MODE5.0 and higherdefined in DDK for Windows 2000; documented by January 2001
0x00000400EVENT_TRACE_BUFFERING_MODE6.0 and higherdefined in DDK for Windows 2000; documented by January 2001
0x00000800EVENT_TRACE_PRIVATE_LOGGER_MODEdefined in DDK for Windows 2000; documented by January 2001
0x00001000EVENT_TRACE_ADD_HEADER_MODE6.0 onlydefined in DDK for Windows 2000; documented by January 2001
0x00002000EVENT_TRACE_USE_KBYTES_FOR_SIZE6.0 and higherdefined in WDK for Windows Vista
0x00004000EVENT_TRACE_USE_GLOBAL_SEQUENCE5.1 and higherdefined in DDK for Windows XP; documented by January 2001
0x00008000EVENT_TRACE_USE_LOCAL_SEQUENCE5.1 and higherdefined in DDK for Windows XP; documented by January 2001
0x00010000EVENT_TRACE_RELOG_MODE6.2 and higherdefined in DDK for Windows XP; documented by January 2003
0x00020000EVENT_TRACE_PRIVATE_IN_PROCdefined in WDK for Windows Vista
0x00040000EVENT_TRACE_BUFFER_INTERFACE_MODE6.1 and higherdefined in Enterprise WDK for 1511
0x00080000EVENT_TRACE_KD_FILTER_MODE6.0 and higherdefined in Enterprise WDK for 1511
0x00100000EVENT_TRACE_MODE_RESERVED6.0 onlydefined in WDK for Windows Vista
EVENT_TRACE_REALTIME_RELOG_MODEdefined in Enterprise WDK for 1511
0x00200000EVENT_TRACE_LOST_EVENTS_DEBUG_MODE6.2 and higherdefined in Enterprise WDK for 1511
0x00400000EVENT_TRACE_STOP_ON_HYBRID_SHUTDOWN6.2 and higherdefined in WDK for Windows 8
0x00800000EVENT_TRACE_PERSIST_ON_HYBRID_SHUTDOWN6.2 and higherdefined in WDK for Windows 8
0x01000000EVENT_TRACE_USE_PAGED_MEMORY6.0 and higherdefined in DDK for Windows XP; documented by January 2003
0x02000000EVENT_TRACE_SYSTEM_LOGGER_MODE6.2 and higherdefined in WDK for Windows 8
0x04000000EVENT_TRACE_COMPRESSED_MODE6.2 and higherdefined in WDK for 1607
0x08000000EVENT_TRACE_INDEPENDENT_SESSION_MODE6.3 and higherdefined in WDK for Windows 8.1
0x10000000EVENT_TRACE_NO_PER_PROCESSOR_BUFFERING6.1 and higherdefined in WDK for Windows 7
0x20000000EVENT_TRACE_BLOCKING_MODEdefined in Enterprise WDK for 1511
0x40000000apparently unused
0x80000000EVENT_TRACE_ADDTO_TRIAGE_DUMP6.2 and higherdefined in WDK for Windows 8

Validation

Very many of the options are incompatible with other LogFileMode flags and in some cases with other WMI_LOGGER_INFORMATION members. By incompatible is here meant that the combination prevents the tracing session from starting: NtTraceControl fails, returning STATUS_INVALID_PARAMETER.

The table for each flag shows the constraints that apply if the flag is set when trying to start a tracing session. These constraints are what the programmer (or the user who configures AutoLogger settings) would need to know if thinking to use the flag. Note that many of these constraints were not enforced immediately that the flag was defined and many seem never to have been formally documented.

Less easily tabulated are the many requirements and inconsistencies that do not prevent a tracing session from starting but are instead corrected silently. When one flag requires another, the natural resolution of the other’s absence is to proceed as if the other had been set. The one is said (below) to imply the other. Where two flags are inconsistent, a resolution that stops short of treating them as incompatible is to accept one but proceed as if the other had been clear. The one is said to override the other. The terminology is in flux and perhaps never will be sorted out: if you don’t like it, please consider that Microsoft, who designed this as part of a product that makes money, is not known to have ever published any serious attempt.

EVENT_TRACE_FILE_MODE_SEQUENTIAL

VersionsConstraints
5.0 and higherinvalid with EVENT_TRACE_FILE_MODE_CIRCULAR
6.0 and higherinvalid with EVENT_TRACE_BUFFERING_MODE

In version 6.0 and higher, EVENT_TRACE_FILE_MODE_SEQUENTIAL is implied if either EVENT_TRACE_FILE_MODE_APPEND or EVENT_TRACE_FILE_MODE_NEWFILE is set.

EVENT_TRACE_FILE_MODE_CIRCULAR

VersionsConstraintsSide-Effects
5.0 and higherinvalid with EVENT_TRACE_FILE_MODE_SEQUENTIAL
5.1 and higherinvalid with EVENT_TRACE_FILE_MODE_APPEND; invalid with EVENT_TRACE_FILE_MODE_NEWFILE
6.0 and higherinvalid with EVENT_TRACE_BUFFERING_MODEcan allow EVENT_TRACE_NONSTOPPABLE_MODE
6.2 and higherrequires MaximumFileSize

Not only are EVENT_TRACE_FILE_MODE_SEQUENTIAL and EVENT_TRACE_FILE_MODE_CIRCULAR opposed in all versions, but the former is a sort of default. In version 6.0 and higher, to omit EVENT_TRACE_FILE_MODE_CIRCULAR is in effect to set EVENT_TRACE_FILE_MODE_SEQUENTIAL unless both EVENT_TRACE_FILE_MODE_APPEND and EVENT_TRACE_FILE_MODE_NEWFILE are also omitted.

Also starting with version 6.0, setting EVENT_TRACE_FILE_MODE_CIRCULAR is one way to allow EVENT_TRACE_NONSTOPPABLE_MODE for an AutoLogger session.

EVENT_TRACE_FILE_MODE_APPEND

VersionsConstraintsSide-Effects
5.1 and higherinvalid with EVENT_TRACE_FILE_MODE_CIRCULAR
6.0 and higherinvalid with EVENT_TRACE_FILE_MODE_PREALLOCATE; invalid with EVENT_TRACE_BUFFERING_MODEimplies EVENT_TRACE_FILE_MODE_SEQUENTIAL
6.1 and higherinvalid with EVENT_TRACE_FILE_MODE_NEWFILE

EVENT_TRACE_FILE_MODE_NEWFILE

VersionsConstraintsSide-Effects
5.1 and higherinvalid with EVENT_TRACE_FILE_MODE_CIRCULAR; requires LogFileName; requires MaximumFileSize
5.2 and higherinvalid with SystemTraceControlGuid
6.0 and higherinvalid with EVENT_TRACE_FILE_MODE_PREALLOCATE; invalid with EVENT_TRACE_BUFFERING_MODE; invalid with 0x00000002 bit in Flags; invalid with CKCLGuidimplies EVENT_TRACE_FILE_MODE_SEQUENTIAL
6.1 and higherinvalid with EVENT_TRACE_FILE_MODE_APPEND
6.2 and higherinvalid with EVENT_TRACE_SYSTEM_LOGGER_MODE

See that EVENT_TRACE_FILE_MODE_NEWFILE is not permitted for some particular tracing sessions. These are identified, originally, by the GUID that is specified in the Guid member of the Wnode or is inferred from the session’s name. The SystemTraceControlGuid and CKCLGuid identify respectively the NT Kernel Logger and the (essentially undocumented) Circular Kernel Context Logger. That it “should not be used for NT kernel logger sessions” has been documented since at least 2003 and generalises in version 6.2 to EVENT_TRACE_SYSTEM_LOGGER_MODE.

Not documented, but perhaps not a surprise, is that EVENT_TRACE_FILE_MODE_NEWFILE is not permitted for AutoLogger sessions. These are distinguished by the 0x00000002 bit in the Flags.

EVENT_TRACE_FILE_MODE_PREALLOCATE

VersionsConstraints
6.0 and higherinvalid with EVENT_TRACE_FILE_MODE_APPEND; invalid with EVENT_TRACE_FILE_MODE_NEWFILE; requires MaximumFileSize

EVENT_TRACE_NONSTOPPABLE_MODE

VersionsConstraints
6.0 and higherrequires at least one other LogFileMode bit, see below; requires 0x00000002 set in Flags

Microsoft included EVENT_TRACE_NONSTOPPABLE_MODE in its documentation of Logging Mode Constants some time between 2010 and 2012 as being “supported on Windows Vista and later.” As the documentation notes, it is intended for tracing sessions that the kernel starts from AutoLogger settings in the registry. Enforcement is through the undocumented Flags bit, which the documented StartTrace function does not set.

Even for AutoLogger sessions, EVENT_TRACE_NONSTOPPABLE_MODE requires one of:

  • EVENT_TRACE_FILE_MODE_CIRCULAR;
  • EVENT_TRACE_BUFFERING_MODE;
  • EVENT_TRACE_REAL_TIME_MODE but without a LogFileName and, in version 6.0, without EVENT_TRACE_DELAY_OPEN_FILE_MODE.

EVENT_TRACE_SECURE_MODE

Nothing invalidates EVENT_TRACE_SECURE_MODE, but it is implied by EVENT_TRACE_BUFFER_INTERFACE_MODE in version 6.1 and higher.

EVENT_TRACE_REAL_TIME_MODE

VersionsSide-Effects
6.0 and highercan allow EVENT_TRACE_NONSTOPPABLE_MODE

Nothing invalidates EVENT_TRACE_REAL_TIME_MODE, but it is overridden by EVENT_TRACE_BUFFERING_MODE in version 6.1 and higher.

In all versions, i.e., 5.0 and higher, EVENT_TRACE_REAL_TIME_MODE is required if all the following are absent:

  • EVENT_TRACE_DELAY_OPEN_FILE_MODE, in versions 5.0 to 6.0;
  • EVENT_TRACE_BUFFERING_MODE, in version 6.0 and higher;
  • LogFileHandle, in versions 5.0 to 5.2;
  • LogFileName, in version 6.0 and higher.

In version 6.0 and higher, setting EVENT_TRACE_REAL_TIME_MODE without also providing a LogFileName or setting EVENT_TRACE_DELAY_OPEN_FILE_MODE allows EVENT_TRACE_NONSTOPPABLE_MODE for an AutoLogger session (see above).

EVENT_TRACE_DELAY_OPEN_FILE_MODE

The original ETW implementation allowed that a log file for a tracing session need not be opened until an event provider actually does write an event for the tracing session to record. This feature is discontinued for version 5.1 but EVENT_TRACE_DELAY_OPEN_FILE_MODE continues to be recognised in the kernel’s code, though without effect in version 6.1 and higher.

VersionsConstraints
5.0 onlyinvalid without LogFileName
6.0 onlyinvalid with EVENT_TRACE_NONSTOPPABLE_MODE if some other LogFileMode bits are clear, see above

In versions 5.0 to 6.0, EVENT_TRACE_DELAY_OPEN_FILE_MODE is required if all the following are absent:

  • EVENT_TRACE_REAL_TIME_MODE;
  • EVENT_TRACE_BUFFERING_MODE, in version 6.0;
  • LogFileHandle, in versions 5.0 to 5.2;
  • LogFileName, in version 6.0.

EVENT_TRACE_BUFFERING_MODE

VersionsConstraintsSide-Effects
6.0 and higherinvalid with LogFileName; invalid with EVENT_TRACE_FILE_MODE_SEQUENTIAL; invalid with EVENT_TRACE_FILE_MODE_CIRCULAR; invalid with EVENT_TRACE_FILE_MODE_APPEND; invalid with EVENT_TRACE_FILE_MODE_NEWFILEcan allow EVENT_TRACE_NONSTOPPABLE_MODE
6.1 and higherinvalid with EVENT_TRACE_BUFFER_INTERFACE_MODEoverrides EVENT_TRACE_REAL_TIME_MODE; overrides FlushTimer
6.1 to 6.2overrides EVENT_TRACE_KD_FILTER_MODE
6.3 and higheroverrides FlushThreshold
1607 and higherallows EVENT_TRACE_COMPRESSED_MODE

In version 6.0 and higher, EVENT_TRACE_BUFFERING_MODE is required if all the following are absent:

  • EVENT_TRACE_REAL_TIME_MODE;
  • EVENT_TRACE_DELAY_OPEN_FILE_MODE, in version 6.0 only;
  • LogFileName.

Also starting with version 6.0, setting EVENT_TRACE_BUFFERING_MODE allows EVENT_TRACE_NONSTOPPABLE_MODE for an AutoLogger session.

EVENT_TRACE_USE_GLOBAL_SEQUENCE

VersionsConstraints
5.1 and higherinvalid with EVENT_TRACE_USE_LOCAL_SEQUENCE

EVENT_TRACE_USE_LOCAL_SEQUENCE

VersionsConstraints
5.1 and higherinvalid with EVENT_TRACE_USE_GLOBAL_SEQUENCE

EVENT_TRACE_RELOG_MODE

VersionsConstraints
6.2 and higherinvalid

Early documentation of EVENT_TRACE_RELOG_MODE was relatively expansive. Nowadays, documentation has it as “reserved for internal use”, and the whole technical content of what the option exists for is “Logs the event without including EVENT_TRACE_HEADER.” Once upon a time, Microsoft continued with

The logger was started to re-log one or more existing log files to a new log file. Therefore, the variable portion of the re-logged event already has a header from the old log file.

The option evidently does something useful, just not something that Microsoft wants programmers writing for themselves. But that’s another story. The option only ever has been meaningful for user-mode tracing sessions. It’s unknown to the kernel until version 6.2 makes a point of rejecting it explicitly.

EVENT_TRACE_BUFFER_INTERFACE_MODE

VersionsConstraintsSide-Effects
6.1 and higherinvalid with EVENT_TRACE_BUFFERING_MODEimplies EVENT_TRACE_SECURE_MODE

EVENT_TRACE_KD_FILTER_MODE

VersionsSide-Effects
6.2 and higheroverrides EVENT_TRACE_USE_PAGED_MEMORY

Nothing invalidates EVENT_TRACE_KD_FILTER_MODE. It is, however, overridden by EVENT_TRACE_BUFFERING_MODE in versions 6.1 to 6.2. In version 6.2, this override of EVENT_TRACE_KD_FILTER_MODE still overrides EVENT_TRACE_USE_PAGED_MEMORY.

EVENT_TRACE_STOP_ON_HYBRID_SHUTDOWN

VersionsConstraints
6.2 and higherinvalid with EVENT_TRACE_PERSIST_ON_HYBRID_SHUTDOWN

EVENT_TRACE_PERSIST_ON_HYBRID_SHUTDOWN

VersionsConstraints
6.2 and higherinvalid with EVENT_TRACE_STOP_ON_HYBRID_SHUTDOWN

EVENT_TRACE_USE_PAGED_MEMORY

VersionsConstraints
6.2 and higherinvalid with EVENT_TRACE_SYSTEM_LOGGER_MODE

A tracing session that has kernel-mode buffers uses non-paged memory by default but can specify EVENT_TRACE_USE_PAGED_MEMORY. The buffers are then reserved in paged memory, of course. This is not suitable for kernel-mode event providers, which are free to write events when access to paged memory is forbidden. This is in general not a problem if such providers never are enabled for the session, but to specify EVENT_TRACE_SYSTEM_LOGGER_MODE is to want from the start that the kernel is an event provider and is ruled out.

Specifying EVENT_TRACE_KD_FILTER_MODE also declares an intention to receive events when paged memory may be out of bounds, but the resolution (also in version 6.2 and higher) is just that EVENT_TRACE_USE_PAGED_MEMORY is overridden.

EVENT_TRACE_SYSTEM_LOGGER_MODE

VersionsConstraints
6.2 and higherinvalid with EVENT_TRACE_FILE_MODE_NEWFILE; invalid with EVENT_TRACE_USE_PAGED_MEMORY

EVENT_TRACE_COMPRESSED_MODE

VersionsConstraints
6.2 to 1511invalid
1607 and higherrequires EVENT_TRACE_BUFFERING_MODE

Compression of buffers for writing to the log file dates from version 6.2 for tracing sessions that have user-mode buffers and are managed by NTDLL instead of the kernel. The compression functionality eventually gets some support for kernel-mode tracing sessions in the 1607 release of Windows 10. Until then, the kernel explicitly rejects EVENT_TRACE_COMPRESSED_MODE as invalid.