DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
EventLog.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"
9
10#if defined(_WIN32)
11#include <windows.h>
12#endif
13
14namespace DotNetDupe {
15 namespace System {
16 namespace Diagnostics {
17
22 enum class EventLogEntryType {
23 Error = 1,
24 Warning = 2,
25 Information = 4,
28 };
29
34 class EventLogEntry : public Object {
35 public:
38
45 DOTNETDUPE_API EventLogEntry(const String& sMessage, EventLogEntryType eType, int iInstanceId, const String& sSource, const DateTimeOffset& dtTimeGenerated);
46
49 String GetMessage() const { return m_sMessage; }
50
53 EventLogEntryType GetEntryType() const { return m_eEntryType; }
54
57 int GetInstanceId() const { return m_iInstanceId; }
58
61 String GetSource() const { return m_sSource; }
62
65 DateTimeOffset GetTimeGenerated() const { return m_dtTimeGenerated; }
66
67 private:
68 String m_sMessage;
69 EventLogEntryType m_eEntryType;
70 int m_iInstanceId;
71 String m_sSource;
72 DateTimeOffset m_dtTimeGenerated;
73 };
74
83 class EventLog : public Object {
84 public:
87
90 DOTNETDUPE_API EventLog(const String& sLogName);
91
95 DOTNETDUPE_API EventLog(const String& sLogName, const String& sMachineName);
96
101 DOTNETDUPE_API EventLog(const String& sLogName, const String& sMachineName, const String& sSource);
102
104 DOTNETDUPE_API virtual ~EventLog();
105
108 String GetLog() const { return m_sLogName; }
109
112 void SetLog(const String& sLogName) { m_sLogName = sLogName; }
113
116 String GetMachineName() const { return m_sMachineName; }
117
120 void SetMachineName(const String& sMachineName) { m_sMachineName = sMachineName; }
121
124 String GetSource() const { return m_sSource; }
125
128 void SetSource(const String& sSource) { m_sSource = sSource; }
129
133
136 DOTNETDUPE_API void WriteEntry(const String& sMessage);
137
141 DOTNETDUPE_API void WriteEntry(const String& sMessage, EventLogEntryType eType);
142
147 DOTNETDUPE_API void WriteEntry(const String& sMessage, EventLogEntryType eType, int iEventID);
148
152 DOTNETDUPE_API static void WriteEntry(const String& sSource, const String& sMessage);
153
158 DOTNETDUPE_API static void WriteEntry(const String& sSource, const String& sMessage, EventLogEntryType eType);
159
165 DOTNETDUPE_API static void WriteEntry(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID);
166
170 DOTNETDUPE_API static bool SourceExists(const String& sSource);
171
176 DOTNETDUPE_API static bool SourceExists(const String& sSource, const String& sMachineName);
177
181 DOTNETDUPE_API static void CreateEventSource(const String& sSource, const String& sLogName);
182
185 DOTNETDUPE_API static void Delete(const String& sLogName);
186
190 DOTNETDUPE_API static void Delete(const String& sLogName, const String& sMachineName);
191
194 DOTNETDUPE_API static void DeleteEventSource(const String& sSource);
195
199 DOTNETDUPE_API static void DeleteEventSource(const String& sSource, const String& sMachineName);
200
204 DOTNETDUPE_API static bool Exists(const String& sLogName);
205
210 DOTNETDUPE_API static bool Exists(const String& sLogName, const String& sMachineName);
211
215
220
222 DOTNETDUPE_API void Clear();
223
225 DOTNETDUPE_API void Close();
226
227 private:
228 String m_sLogName;
229 String m_sMachineName;
230 String m_sSource;
231
232#if defined(_WIN32)
233 static EventLogEntryType MapWin32EventType(WORD wType);
234 static EventLogEntry ParseWin32Record(const PEVENTLOGRECORD pRec);
235 static void ProcessWin32EventBuffer(BYTE* buffer, DWORD dwBytesRead, Collections::Generic::List<EventLogEntry>& lstEntries);
236 static void ReadWin32EventLog(const String& sLogName, Collections::Generic::List<EventLogEntry>& lstEntries);
237 static void WriteWin32EventLog(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID);
238 static bool CreateWin32EventSource(const String& sSource, const String& sLogName);
239 static bool Win32SourceExists(const String& sSource);
240 static void DeleteWin32EventSource(const String& sSource);
241#else
242 static void WriteLinuxSyslog(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID);
243 static EventLogEntry ParseSyslogLine(const String& line);
244 static void ReadLinuxSyslogFile(const String& sFilePath, Collections::Generic::List<EventLogEntry>& lstEntries);
245 static void ReadLinuxSyslog(Collections::Generic::List<EventLogEntry>& lstEntries);
246#endif
247 static void RecordInternalLogEntry(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID);
248 static void PurgeSourcesForLog(const String& sLogName);
249 };
250
251 }
252 }
253}
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 point in time, typically expressed as a date and time of day, relative to Coordinated Un...
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.
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...
Encapsulates a single record in the event log.
Definition EventLog.h:34
DateTimeOffset GetTimeGenerated() const
Gets the local time at which this event was generated.
Definition EventLog.h:65
String GetSource() const
Gets the name of the software that registered the event.
Definition EventLog.h:61
EventLogEntry()
Default constructor initializing an empty entry.
Definition EventLog.cpp:42
int GetInstanceId() const
Gets the resource identifier / event ID.
Definition EventLog.h:57
EventLogEntryType GetEntryType() const
Gets the event type of the entry.
Definition EventLog.h:53
String GetMessage() const
Gets the message associated with the event.
Definition EventLog.h:49
static void DeleteEventSource(const String &sSource)
Removes an event source registration from the local computer.
Definition EventLog.cpp:418
void SetSource(const String &sSource)
Sets the source name to register and use when writing to the event log.
Definition EventLog.h:128
void SetMachineName(const String &sMachineName)
Sets the name of the computer on which the event log resides.
Definition EventLog.h:120
void Close()
Closes the event log and releases read/write handles.
Definition EventLog.cpp:491
String GetMachineName() const
Gets the name of the computer on which the event log resides.
Definition EventLog.h:116
String GetSource() const
Gets the source name to register and use when writing to the event log.
Definition EventLog.h:124
EventLog()
Initializes a new instance of the EventLog class targeting the Application log.
Definition EventLog.cpp:50
static Collections::Generic::List< EventLog > GetEventLogs()
Searches for all event logs on the local computer.
Definition EventLog.cpp:461
static void Delete(const String &sLogName)
Removes an event log from the local computer.
Definition EventLog.cpp:390
void Clear()
Removes all entries from the event log.
Definition EventLog.cpp:475
void WriteEntry(const String &sMessage)
Writes an information entry with the specified message to the event log.
Definition EventLog.cpp:303
String GetLog() const
Gets the name of the log to read from or write to.
Definition EventLog.h:108
static bool SourceExists(const String &sSource)
Determines whether the specified event source is registered on the local computer.
Definition EventLog.cpp:354
static void CreateEventSource(const String &sSource, const String &sLogName)
Establishes the specified source name as a valid event source for writing to a log.
Definition EventLog.cpp:368
static bool Exists(const String &sLogName)
Determines whether the log exists on the local computer.
Definition EventLog.cpp:439
void SetLog(const String &sLogName)
Sets the name of the log to read from or write to.
Definition EventLog.h:112
Collections::Generic::List< EventLogEntry > GetEntries() const
Gets the contents of the event log as a list of entries.
Definition EventLog.cpp:284
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
EventLogEntryType
Defines the event type of an event log entry.
Definition EventLog.h:22
@ FailureAudit
An audit event tracking failed security access.
Definition EventLog.h:27
@ SuccessAudit
An audit event tracking successful security access.
Definition EventLog.h:26