DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
EtwLogReader.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common.h"
4#include "System/Object.h"
5#include "System/String.h"
7#include "System/Action.h"
10
11#if defined(_WIN32)
12#include <windows.h>
13#include <winevt.h>
14#endif
15
16namespace DotNetDupe {
17 namespace System {
18 namespace Diagnostics {
19
31
34 enum class EtwEventLevel {
35 All = 0,
36 Critical = 1,
37 Error = 2,
38 Warning = 3,
39 Info = 4,
41 };
42
46 unsigned long long uCriticalCount;
47 unsigned long long uErrorCount;
48 unsigned long long uWarningCount;
49 unsigned long long uInfoCount;
50 unsigned long long uVerboseCount;
51 };
52
60 class EtwLogReader : public Object {
61 public:
64
67
71
75 DOTNETDUPE_API static unsigned long long GetChannelEventCount(const String& sChannelName);
76
81
86
91 DOTNETDUPE_API static Collections::Generic::List<EtwEvent> ReadEvents(const String& sChannelName, int iMaxEvents);
92
98 DOTNETDUPE_API static Collections::Generic::List<EtwEvent> ReadEvents(const String& sChannelName, int iMaxEvents, int iStartIndex);
99
106 DOTNETDUPE_API static Collections::Generic::List<EtwEvent> ReadEvents(const String& sChannelName, int iMaxEvents, int iStartIndex, bool bReverseDirection);
107
115 DOTNETDUPE_API static Collections::Generic::List<EtwEvent> ReadEvents(const String& sChannelName, int iMaxEvents, int iStartIndex, bool bReverseDirection, EtwEventLevel level);
116
122 DOTNETDUPE_API void StartListening(const String& sChannelName, Action<const EtwEvent&> fnCallback);
123
126
129 bool IsListening() const { return m_bListening; }
130
133 String GetListeningChannel() const { return m_sListeningChannel; }
134
135 private:
136 bool m_bListening;
137 String m_sListeningChannel;
138 void* m_pSubscriptionHandle;
139 Action<const EtwEvent&> m_fnCallback;
140
141 static void RegisterChannelIfNew(const String& sChannelName);
142#if defined(_WIN32)
143 static DWORD WINAPI Win32EvtSubscribeCallback(EVT_SUBSCRIBE_NOTIFY_ACTION action, PVOID pUserContext, EVT_HANDLE hEvent);
144 static EVT_HANDLE SubscribeWin32Channel(const String& sChannelName, Action<const EtwEvent&>* pCallback);
145 static void EnumerateWin32Channels(Collections::Generic::List<String>& lstChannels);
146 static void FormatEtwEventXml(EVT_HANDLE hEvt, EtwEvent& evt);
147 static void FormatEtwEventMessage(EVT_HANDLE hEvt, EtwEvent& evt);
148 static EtwEvent ProcessSingleEtwEvent(EVT_HANDLE hContext, EVT_HANDLE hEvt, const String& sChannelName);
149 static bool IterateEvtBatch(EVT_HANDLE hContext, EVT_HANDLE* arrEvents, DWORD dwReturned, const String& sChannelName, int iMaxEvents, EtwEventLevel level, Collections::Generic::List<EtwEvent>& lstEvents);
150 static void IterateEvtResults(EVT_HANDLE hContext, EVT_HANDLE hResults, const String& sChannelName, int iMaxEvents, EtwEventLevel level, Collections::Generic::List<EtwEvent>& lstEvents);
151 static void ReadWin32EvtChannel(const String& sChannelName, int iMaxEvents, int iStartIndex, bool bReverseDirection, EtwEventLevel level, Collections::Generic::List<EtwEvent>& lstEvents);
152 static unsigned long long FastQueryLevelCount(const std::wstring& wChannel, const wchar_t* pwszFilter);
153 static void CountWin32EventsByLevel(const std::wstring& wChannel, EtwEventLevelCounts& counts);
154#endif
155 };
156
157 }
158 }
159}
Encapsulates a delegate method that has parameters and returns void.
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Encapsulates a method that has parameters and does not return a value.
Definition Action.h:46
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
EtwLogReader()
Initializes a new instance of EtwLogReader.
void StopListening()
Terminates active real-time event listening and closes subscription handles.
static Collections::Generic::List< String > GetEventChannels()
Enumerates all registered ETW and Windows Event Log channel paths.
static EtwEventLevelCounts GetChannelEventLevelCounts(const String &sChannelName)
Aggregates the count of events in a channel broken down by severity level.
static Collections::Generic::List< EtwEvent > ReadEvents(const String &sChannelName)
Reads all available events from the specified channel.
void StartListening(const String &sChannelName, Action< const EtwEvent & > fnCallback)
Initiates an asynchronous real-time subscription to events on the specified channel.
static unsigned long long GetChannelEventCount(const String &sChannelName)
Retrieves total number of recorded events in a channel.
String GetListeningChannel() const
Retrieves the name of the channel currently being listened to.
bool IsListening() const
Indicates whether an active subscription is running.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
EtwEventLevel
Filter levels corresponding to standard Windows ETW severity classifications.
@ Info
Normal operational informational events.
@ All
All events regardless of level.
@ Verbose
Detailed developer or diagnostic trace information.
Represents an individual Event Tracing for Windows (ETW) event record.
int iLevel
Severity level of the event.
String sMessage
Formatted textual description of the event.
String sRawXml
Raw XML representation of the ETW payload.
int iEventId
Numeric identifier for the event type.
DateTimeOffset dtTimeCreated
Precise timestamp when the event was generated.
String sChannelName
Name of the event log channel (e.g. "Application", "System").
String sProviderName
Name or GUID of the publishing event provider.
Aggregate counts of events partitioned by severity level within a channel.
unsigned long long uVerboseCount
Number of Verbose level events.
unsigned long long uCriticalCount
Number of Critical level events.
unsigned long long uErrorCount
Number of Error level events.
unsigned long long uInfoCount
Number of Information level events.
unsigned long long uWarningCount
Number of Warning level events.