DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
EventLog.cpp
Go to the documentation of this file.
1#include "pch.h"
7#include "System/IO/File.h"
8#include "System/IO/Path.h"
10#include "System/TimeProvider.h"
12
13#include <mutex>
14#include <vector>
15#include <map>
16#include <fstream>
17#include <sstream>
18
19#if defined(_WIN32)
20#include <windows.h>
21#else
22#include <syslog.h>
23#include <sys/stat.h>
24#endif
25
26namespace DotNetDupe {
27 namespace System {
28 namespace Diagnostics {
29
30 struct EventLogStoreEntry {
31 String sMessage;
33 int iInstanceId;
34 String sSource;
35 DateTimeOffset dtTimeGenerated;
36 };
37
38 static std::mutex s_mtxEventLog;
39 static std::map<String, String> s_mapSourceToLog;
40 static std::map<String, std::vector<EventLogStoreEntry>> s_mapLogEntries;
41
43 : m_sMessage(""), m_eEntryType(EventLogEntryType::Information), m_iInstanceId(0), m_sSource(""), m_dtTimeGenerated(DateTimeOffset::Now()) {
44 }
45
46 EventLogEntry::EventLogEntry(const String& sMessage, EventLogEntryType eType, int iInstanceId, const String& sSource, const DateTimeOffset& dtTimeGenerated)
47 : m_sMessage(sMessage), m_eEntryType(eType), m_iInstanceId(iInstanceId), m_sSource(sSource), m_dtTimeGenerated(dtTimeGenerated) {
48 }
49
51 : m_sLogName("Application"), m_sMachineName("."), m_sSource("") {
52 }
53
54 EventLog::EventLog(const String& sLogName)
55 : m_sLogName(sLogName), m_sMachineName("."), m_sSource("") {
56 if (m_sLogName.IsEmpty()) m_sLogName = "Application";
57 }
58
59 EventLog::EventLog(const String& sLogName, const String& sMachineName)
60 : m_sLogName(sLogName), m_sMachineName(sMachineName), m_sSource("") {
61 if (m_sLogName.IsEmpty()) m_sLogName = "Application";
62 if (m_sMachineName.IsEmpty()) m_sMachineName = ".";
63 }
64
65 EventLog::EventLog(const String& sLogName, const String& sMachineName, const String& sSource)
66 : m_sLogName(sLogName), m_sMachineName(sMachineName), m_sSource(sSource) {
67 if (m_sLogName.IsEmpty()) m_sLogName = "Application";
68 if (m_sMachineName.IsEmpty()) m_sMachineName = ".";
69 }
70
73
74#if defined(_WIN32)
75 EventLogEntryType EventLog::MapWin32EventType(WORD wType) {
77 if (wType == EVENTLOG_ERROR_TYPE) return EventLogEntryType::Error;
78 if (wType == EVENTLOG_WARNING_TYPE) return EventLogEntryType::Warning;
79 if (wType == EVENTLOG_AUDIT_SUCCESS) return EventLogEntryType::SuccessAudit;
80 if (wType == EVENTLOG_AUDIT_FAILURE) return EventLogEntryType::FailureAudit;
82 }
83
84 EventLogEntry EventLog::ParseWin32Record(const PEVENTLOGRECORD pRec) {
86 EventLogEntryType eType = MapWin32EventType(pRec->EventType);
87 std::string sSrc = Utils::StringConvert::WCharToUtf8((wchar_t*)((BYTE*)pRec + sizeof(EVENTLOGRECORD)));
88 String sMsg = "";
89 if (pRec->NumStrings > 0) {
90 std::string sNarrowMsg = Utils::StringConvert::WCharToUtf8((wchar_t*)((BYTE*)pRec + pRec->StringOffset));
91 sMsg = String(sNarrowMsg.c_str());
92 }
93
95 int64_t iTicks = ((int64_t)pRec->TimeGenerated + 62135596800LL) * 10000000LL;
96 return EventLogEntry(sMsg, eType, (int)pRec->EventID, String(sSrc.c_str()), DateTimeOffset(iTicks));
97 }
98
99 void EventLog::ProcessWin32EventBuffer(BYTE* buffer, DWORD dwBytesRead, Collections::Generic::List<EventLogEntry>& lstEntries) {
101 DWORD dwOffset = 0;
102 while (dwOffset < dwBytesRead) {
103 PEVENTLOGRECORD pRec = (PEVENTLOGRECORD)&buffer[dwOffset];
104 lstEntries.Add(ParseWin32Record(pRec));
105 dwOffset += pRec->Length;
106 }
107 }
108
111 if (eType == EventLogEntryType::Error) return EVENTLOG_ERROR_TYPE;
112 if (eType == EventLogEntryType::Warning) return EVENTLOG_WARNING_TYPE;
113 if (eType == EventLogEntryType::SuccessAudit) return EVENTLOG_AUDIT_SUCCESS;
114 if (eType == EventLogEntryType::FailureAudit) return EVENTLOG_AUDIT_FAILURE;
115 return EVENTLOG_INFORMATION_TYPE;
116 }
117
118 static void ValidateWin32ReportResult(BOOL bReported, DWORD dwErr, const String& sSource) {
120 if (!bReported) {
121 if (dwErr == ERROR_ACCESS_DENIED) {
122 throw UnauthorizedAccessException("Access denied writing to EventLog for source: " + sSource);
123 }
124 throw ComponentModel::Win32Exception(dwErr, "Failed to report event to EventLog: " + sSource);
125 }
126 }
127
128 static HANDLE OpenWin32EventLogHandle(const String& sLogName) {
130 std::string sStdLogName(sLogName.GetRawString() ? sLogName.GetRawString() : "");
131 std::wstring wLogName(sStdLogName.begin(), sStdLogName.end());
132 HANDLE h = ::OpenEventLogW(NULL, wLogName.c_str());
133 if (!h) {
134 DWORD dwErr = ::GetLastError();
135 if (dwErr == ERROR_ACCESS_DENIED) throw UnauthorizedAccessException("Access denied opening EventLog: " + sLogName);
136 if (dwErr == ERROR_FILE_NOT_FOUND || dwErr == ERROR_PATH_NOT_FOUND) throw ArgumentException("EventLog not found: " + sLogName);
137 throw ComponentModel::Win32Exception(dwErr, "Failed to open EventLog: " + sLogName);
138 }
139 return h;
140 }
141
142 void EventLog::ReadWin32EventLog(const String& sLogName, Collections::Generic::List<EventLogEntry>& lstEntries) {
144 HANDLE hEventLog = OpenWin32EventLogHandle(sLogName);
145 DWORD dwBytesRead = 0, dwNeeded = 0;
146 BYTE buffer[0x10000];
147 while (::ReadEventLogW(hEventLog, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, buffer, sizeof(buffer), &dwBytesRead, &dwNeeded)) {
148 ProcessWin32EventBuffer(buffer, dwBytesRead, lstEntries);
149 }
150 ::CloseEventLog(hEventLog);
151 }
152
153 static HANDLE RegisterWin32EventSourceHandle(const String& sSource) {
155 std::string sStdSource(sSource.GetRawString() ? sSource.GetRawString() : "");
156 std::wstring wSource(sStdSource.begin(), sStdSource.end());
157 HANDLE h = ::RegisterEventSourceW(NULL, wSource.c_str());
158 if (!h) {
159 DWORD dwErr = ::GetLastError();
160 if (dwErr == ERROR_ACCESS_DENIED) throw UnauthorizedAccessException("Access denied registering EventSource: " + sSource);
161 throw ComponentModel::Win32Exception(dwErr, "Failed to register EventSource: " + sSource);
162 }
163 return h;
164 }
165
166 void EventLog::WriteWin32EventLog(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID) {
168 HANDLE hEventLog = RegisterWin32EventSourceHandle(sSource);
169 std::string sStdMsg(sMessage.GetRawString() ? sMessage.GetRawString() : "");
170 std::wstring wMsg(sStdMsg.begin(), sStdMsg.end());
171 LPCWSTR pStrings[1] = { wMsg.c_str() };
172 BOOL bReported = ::ReportEventW(hEventLog, MapEventLogEntryTypeToWin32(eType), 0, (DWORD)iEventID, NULL, 1, 0, pStrings, NULL);
173 DWORD dwErr = ::GetLastError();
174 ::DeregisterEventSource(hEventLog);
175 ValidateWin32ReportResult(bReported, dwErr, sSource);
176 }
177
178 bool EventLog::CreateWin32EventSource(const String& sSource, const String& sLogName) {
180 std::string sStdLog(sLogName.GetRawString() ? sLogName.GetRawString() : "");
181 std::string sStdSrc(sSource.GetRawString() ? sSource.GetRawString() : "");
182 std::wstring wSubKey = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\" +
183 std::wstring(sStdLog.begin(), sStdLog.end()) + L"\\" +
184 std::wstring(sStdSrc.begin(), sStdSrc.end());
185 HKEY hKey = NULL;
186 LONG lRes = ::RegCreateKeyExW(HKEY_LOCAL_MACHINE, wSubKey.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
187 if (lRes == ERROR_SUCCESS) {
188 ::RegCloseKey(hKey);
189 return true;
190 }
191 if (lRes == ERROR_ACCESS_DENIED) {
192 throw UnauthorizedAccessException("Access denied creating EventLog source in registry under HKLM. Administrator privileges required.");
193 }
194 return false;
195 }
196
197 bool EventLog::Win32SourceExists(const String& sSource) {
199 std::string sStdSrc(sSource.GetRawString() ? sSource.GetRawString() : "");
200 const wchar_t* subKeys[] = { L"Application", L"System", L"Security" };
201 for (const wchar_t* pLog : subKeys) {
202 std::wstring wSubKey = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + std::wstring(pLog) + L"\\" + std::wstring(sStdSrc.begin(), sStdSrc.end());
203 HKEY hKey = NULL;
204 if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, wSubKey.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
205 ::RegCloseKey(hKey);
206 return true;
207 }
208 }
209 return false;
210 }
211
212 void EventLog::DeleteWin32EventSource(const String& sSource) {
214 const wchar_t* subKeys[] = { L"Application", L"System", L"Security" };
215 for (const wchar_t* pLog : subKeys) {
216 std::wstring wSubKey = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + std::wstring(pLog) + L"\\" + std::wstring(sSource.GetRawString(), sSource.GetRawString() + sSource.GetLength());
217 LONG lRes = ::RegDeleteKeyW(HKEY_LOCAL_MACHINE, wSubKey.c_str());
218 if (lRes == ERROR_ACCESS_DENIED) {
219 throw UnauthorizedAccessException("Access denied deleting EventLog source from registry under HKLM. Administrator privileges required.");
220 }
221 }
222 }
223#else
224 void EventLog::WriteLinuxSyslog(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID) {
226 int iPriority = LOG_INFO;
227 const char* szLevelStr = "Information";
228 if (eType == EventLogEntryType::Error) { iPriority = LOG_ERR; szLevelStr = "Error"; }
229 else if (eType == EventLogEntryType::Warning) { iPriority = LOG_WARNING; szLevelStr = "Warning"; }
230 else if (eType == EventLogEntryType::SuccessAudit) { iPriority = LOG_NOTICE; szLevelStr = "SuccessAudit"; }
231 else if (eType == EventLogEntryType::FailureAudit) { iPriority = LOG_ALERT; szLevelStr = "FailureAudit"; }
232 const char* pSrc = sSource.GetRawString() ? sSource.GetRawString() : "";
233 const char* pMsg = sMessage.GetRawString() ? sMessage.GetRawString() : "";
234 openlog(pSrc, LOG_PID | LOG_CONS, LOG_USER);
235 syslog(iPriority, "[%s] [EventID %d] %s", szLevelStr, iEventID, pMsg);
236 closelog();
237 }
238
239 EventLogEntry EventLog::ParseSyslogLine(const String& sLine) {
242 std::string line = sLine.GetRawString() ? sLine.GetRawString() : "";
243
244 if (line.find("error") != std::string::npos || line.find("ERR") != std::string::npos || line.find("err") != std::string::npos || line.find("Error") != std::string::npos) {
246 } else if (line.find("warn") != std::string::npos || line.find("WARN") != std::string::npos || line.find("Warn") != std::string::npos) {
248 }
249
250 int iEventId = 0;
251 size_t posId = line.find("[EventID ");
252 if (posId != std::string::npos) {
253 iEventId = std::atoi(line.c_str() + posId + 9);
254 }
255
256 return EventLogEntry(sLine, eType, iEventId, "syslog", DateTimeOffset::Now());
257 }
258
259 void EventLog::ReadLinuxSyslogFile(const String& sFilePath, Collections::Generic::List<EventLogEntry>& lstEntries) {
261 std::ifstream infile(sFilePath.GetRawString() ? sFilePath.GetRawString() : "");
262 if (!infile.is_open()) return;
263
264 std::string line;
265 while (std::getline(infile, line)) {
266 if (line.empty()) continue;
267 lstEntries.Add(ParseSyslogLine(String(line.c_str())));
268 }
269 }
270
271 void EventLog::ReadLinuxSyslog(Collections::Generic::List<EventLogEntry>& lstEntries) {
273 const char* syslogPaths[] = { "/var/log/syslog", "/var/log/messages" };
274 for (const char* path : syslogPaths) {
275 struct stat st;
276 if (stat(path, &st) == 0) {
277 ReadLinuxSyslogFile(path, lstEntries);
278 break;
279 }
280 }
281 }
282#endif
283
286 std::lock_guard<std::mutex> lock(s_mtxEventLog);
288#if defined(_WIN32)
289 ReadWin32EventLog(m_sLogName, lstEntries);
290#else
291 ReadLinuxSyslog(lstEntries);
292#endif
294 auto it = s_mapLogEntries.find(m_sLogName);
295 if (it != s_mapLogEntries.end()) {
296 for (const auto& entry : it->second) {
297 lstEntries.Add(EventLogEntry(entry.sMessage, entry.eType, entry.iInstanceId, entry.sSource, entry.dtTimeGenerated));
298 }
299 }
300 return lstEntries;
301 }
302
303 void EventLog::WriteEntry(const String& sMessage) {
305 }
306
307 void EventLog::WriteEntry(const String& sMessage, EventLogEntryType eType) {
308 WriteEntry(sMessage, eType, 0);
309 }
310
311 void EventLog::WriteEntry(const String& sMessage, EventLogEntryType eType, int iEventID) {
312 String sEffectiveSource = m_sSource.IsEmpty() ? m_sLogName : m_sSource;
313 WriteEntry(sEffectiveSource, sMessage, eType, iEventID);
314 }
315
316 void EventLog::WriteEntry(const String& sSource, const String& sMessage) {
317 WriteEntry(sSource, sMessage, EventLogEntryType::Information, 0);
318 }
319
320 void EventLog::WriteEntry(const String& sSource, const String& sMessage, EventLogEntryType eType) {
321 WriteEntry(sSource, sMessage, eType, 0);
322 }
323
324 void EventLog::RecordInternalLogEntry(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID) {
326 String sTargetLog = "Application";
327 auto itSource = s_mapSourceToLog.find(sSource);
328 if (itSource != s_mapSourceToLog.end()) {
329 sTargetLog = itSource->second;
330 } else {
331 s_mapSourceToLog[sSource] = sTargetLog;
332 }
333 EventLogStoreEntry entry{ sMessage, eType, iEventID, sSource, DateTimeOffset::Now() };
334 s_mapLogEntries[sTargetLog].push_back(entry);
335 }
336
337 void EventLog::WriteEntry(const String& sSource, const String& sMessage, EventLogEntryType eType, int iEventID) {
339 if (sSource.IsEmpty()) {
340 throw ArgumentException("Source cannot be empty when writing to event log.");
341 }
342
344#if defined(_WIN32)
345 WriteWin32EventLog(sSource, sMessage, eType, iEventID);
346#else
347 WriteLinuxSyslog(sSource, sMessage, eType, iEventID);
348#endif
350 std::lock_guard<std::mutex> lock(s_mtxEventLog);
351 RecordInternalLogEntry(sSource, sMessage, eType, iEventID);
352 }
353
354 bool EventLog::SourceExists(const String& sSource) {
355 return SourceExists(sSource, ".");
356 }
357
358 bool EventLog::SourceExists(const String& sSource, const String& sMachineName) {
360 if (sSource.IsEmpty()) return false;
361#if defined(_WIN32)
362 if (Win32SourceExists(sSource)) return true;
363#endif
364 std::lock_guard<std::mutex> lock(s_mtxEventLog);
365 return s_mapSourceToLog.find(sSource) != s_mapSourceToLog.end();
366 }
367
368 void EventLog::CreateEventSource(const String& sSource, const String& sLogName) {
370 if (sSource.IsEmpty()) throw ArgumentException("Source cannot be empty.");
371 String sEffectiveLog = sLogName.IsEmpty() ? String("Application") : sLogName;
372#if defined(_WIN32)
373 try {
374 CreateWin32EventSource(sSource, sEffectiveLog);
375 } catch (const UnauthorizedAccessException&) {
376 // Fallback to in-memory store in non-elevated environments
377 }
378#endif
379 std::lock_guard<std::mutex> lock(s_mtxEventLog);
380 auto it = s_mapSourceToLog.find(sSource);
381 if (it != s_mapSourceToLog.end() && it->second != sEffectiveLog) {
382 throw ArgumentException("Source already exists registered to another log.");
383 }
384 s_mapSourceToLog[sSource] = sEffectiveLog;
385 if (s_mapLogEntries.find(sEffectiveLog) == s_mapLogEntries.end()) {
386 s_mapLogEntries[sEffectiveLog] = std::vector<EventLogStoreEntry>();
387 }
388 }
389
390 void EventLog::Delete(const String& sLogName) {
391 Delete(sLogName, ".");
392 }
393
394 void EventLog::PurgeSourcesForLog(const String& sLogName) {
396 std::vector<String> vSourcesToRemove;
397 for (const auto& pair : s_mapSourceToLog) {
398 if (pair.second == sLogName) vSourcesToRemove.push_back(pair.first);
399 }
400 for (const auto& sSource : vSourcesToRemove) {
401 s_mapSourceToLog.erase(sSource);
402 }
403 }
404
405 void EventLog::Delete(const String& sLogName, const String& sMachineName) {
407 if (sLogName.IsEmpty()) throw ArgumentException("Log name cannot be empty.");
408#if defined(_WIN32)
409 std::string sStdLog(sLogName.GetRawString() ? sLogName.GetRawString() : "");
410 std::wstring wLogKey = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + std::wstring(sStdLog.begin(), sStdLog.end());
411 ::RegDeleteKeyW(HKEY_LOCAL_MACHINE, wLogKey.c_str());
412#endif
413 std::lock_guard<std::mutex> lock(s_mtxEventLog);
414 s_mapLogEntries.erase(sLogName);
415 PurgeSourcesForLog(sLogName);
416 }
417
418 void EventLog::DeleteEventSource(const String& sSource) {
419 DeleteEventSource(sSource, ".");
420 }
421
422 void EventLog::DeleteEventSource(const String& sSource, const String& sMachineName) {
424 if (sSource.IsEmpty()) throw ArgumentException("Source cannot be empty.");
425#if defined(_WIN32)
426 try {
427 DeleteWin32EventSource(sSource);
428 } catch (const UnauthorizedAccessException&) {
429 // Fallback to in-memory store in non-elevated environments
430 }
431#endif
432 std::lock_guard<std::mutex> lock(s_mtxEventLog);
433 if (s_mapSourceToLog.find(sSource) == s_mapSourceToLog.end()) {
434 throw ArgumentException("The event source does not exist.");
435 }
436 s_mapSourceToLog.erase(sSource);
437 }
438
439 bool EventLog::Exists(const String& sLogName) {
440 return Exists(sLogName, ".");
441 }
442
443 bool EventLog::Exists(const String& sLogName, const String& sMachineName) {
445 if (sLogName.IsEmpty()) return false;
446#if defined(_WIN32)
447 std::string sStdLog(sLogName.GetRawString() ? sLogName.GetRawString() : "");
448 std::wstring wSubKey = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + std::wstring(sStdLog.begin(), sStdLog.end());
449 HKEY hKey = NULL;
450 if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, wSubKey.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
451 ::RegCloseKey(hKey);
452 return true;
453 }
454#else
455 if (sLogName == "Application" || sLogName == "System") return true;
456#endif
457 std::lock_guard<std::mutex> lock(s_mtxEventLog);
458 return s_mapLogEntries.find(sLogName) != s_mapLogEntries.end();
459 }
460
464
467 std::lock_guard<std::mutex> lock(s_mtxEventLog);
469 for (const auto& pair : s_mapLogEntries) {
470 lstLogs.Add(EventLog(pair.first, sMachineName));
471 }
472 return lstLogs;
473 }
474
477#if defined(_WIN32)
478 std::string sStdLog(m_sLogName.GetRawString() ? m_sLogName.GetRawString() : "");
479 std::wstring wLog(sStdLog.begin(), sStdLog.end());
480 HANDLE hLog = ::OpenEventLogW(NULL, wLog.c_str());
481 if (hLog != NULL) {
482 ::ClearEventLogW(hLog, NULL);
483 ::CloseEventLog(hLog);
484 }
485#endif
487 std::lock_guard<std::mutex> lock(s_mtxEventLog);
488 s_mapLogEntries[m_sLogName].clear();
489 }
490
493 }
494
495 }
496 }
497}
Defines the exception thrown when an invalid argument is provided to a method.
Provides information about, and means to manipulate, the current environment and platform.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file.
Defines the exception thrown when a method call is invalid for the object's current state.
Utility routines for high-performance UTF-8, UTF-16, and wide-character string conversions.
Provides an abstraction for time, timestamps, and elapsed time calculation.
The exception that is thrown when the operating system denies access because of an I/O error or a spe...
Exception thrown for a Win32 or platform-native error code.
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
void Add(const T &item)
Adds an object to the end of the List.
Definition List.h:138
Exception thrown for a Win32 or POSIX platform error code.
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
static DateTimeOffset Now()
Gets a DateTimeOffset object that is set to the current date and time on the current computer,...
Encapsulates a single record in the event log.
Definition EventLog.h:34
EventLogEntry()
Default constructor initializing an empty entry.
Definition EventLog.cpp:42
static void DeleteEventSource(const String &sSource)
Removes an event source registration from the local computer.
Definition EventLog.cpp:418
void Close()
Closes the event log and releases read/write handles.
Definition EventLog.cpp:491
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
static bool SourceExists(const String &sSource)
Determines whether the specified event source is registered on the local computer.
Definition EventLog.cpp:354
virtual ~EventLog()
Virtual destructor.
Definition EventLog.cpp:71
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
Collections::Generic::List< EventLogEntry > GetEntries() const
Gets the contents of the event log as a list of entries.
Definition EventLog.cpp:284
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
String()
Initializes a new instance of the String class to an empty string.
Definition String.cpp:64
const char * GetRawString() const
Definition String.cpp:230
The exception that is thrown when the operating system denies access because of an I/O or security er...
UnauthorizedAccessException()
Initializes a new instance of the UnauthorizedAccessException class with a default message.
Definition Exception.cpp:52
static std::string WCharToUtf8(const wchar_t *pWStr)
Converts a null-terminated UTF-16 wchar_t string into a UTF-8 std::string.
static std::map< String, std::vector< EventLogStoreEntry > > s_mapLogEntries
Definition EventLog.cpp:40
static std::map< String, String > s_mapSourceToLog
Definition EventLog.cpp:39
static std::mutex s_mtxEventLog
Definition EventLog.cpp:38
EventLogEntryType
Defines the event type of an event log entry.
Definition EventLog.h:22
@ Warning
A warning event indicating a potential problem.
Definition EventLog.h:24
@ Error
An error event indicating significant problem.
Definition EventLog.h:23
@ Information
An informational event representing successful milestones.
Definition EventLog.h:25
@ FailureAudit
An audit event tracking failed security access.
Definition EventLog.h:27
@ SuccessAudit
An audit event tracking successful security access.
Definition EventLog.h:26
static WORD MapEventLogEntryTypeToWin32(EventLogEntryType eType)
Definition EventLog.cpp:109
static void ValidateWin32ReportResult(BOOL bReported, DWORD dwErr, const String &sSource)
Definition EventLog.cpp:118
static HANDLE OpenWin32EventLogHandle(const String &sLogName)
Definition EventLog.cpp:128
static HANDLE RegisterWin32EventSourceHandle(const String &sSource)
Definition EventLog.cpp:153