Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Event Source Name in EventLog Event Log entries #182

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions LogMonitor/src/LogMonitor/EventMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@
// Extract the variant values for each queried property. If the variant failed to get a valid type
// set a default value.
//
std::wstring providerName = (EvtVarTypeString != variants[0].Type) ? L"" : variants[0].StringVal;
std::wstring providerName = (EvtVarTypeString != variants[EvtSystemProviderName].Type) ? L"" : variants[EvtSystemProviderName].StringVal;

Check warning on line 508 in LogMonitor/src/LogMonitor/EventMonitor.cpp

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Lines should be <= 120 characters long [whitespace/line_length] [2] Raw Output: LogMonitor/src/LogMonitor/EventMonitor.cpp:508: Lines should be <= 120 characters long [whitespace/line_length] [2]
std::wstring channelName = (EvtVarTypeString != variants[1].Type) ? L"" : variants[1].StringVal;
pLogEntry->eventId = (EvtVarTypeUInt16 != variants[2].Type) ? 0 : variants[2].UInt16Val;
UINT8 level = (EvtVarTypeByte != variants[3].Type) ? 0 : variants[3].ByteVal;
Expand Down Expand Up @@ -561,6 +561,7 @@
if (status == ERROR_SUCCESS)
{
pLogEntry->source = L"EventLog";
pLogEntry->eventSource = providerName;
pLogEntry->eventTime = Utility::FileTimeToString(fileTimeCreated);
pLogEntry->eventChannel = channelName;
pLogEntry->eventLevel = c_LevelToString[static_cast<UINT8>(level)];
Expand All @@ -572,13 +573,14 @@
} else {
std::wstring logFmt;
if (Utility::CompareWStrings(m_logFormat, L"XML")) {
logFmt = L"<Log><Source>%s</Source><LogEntry><Time>%s</Time>"
logFmt = L"<Log><Source>%s</Source><LogEntry><EventSource>%s</EventSource><Time>%s</Time>"
L"<Channel>%s</Channel><Level>%s</Level>"
L"<EventId>%u</EventId><Message>%s</Message>"
L"</LogEntry></Log>";
} else {
logFmt = L"{\"Source\": \"%s\","
L"\"LogEntry\": {"
L"\"EventSource\": \"%s\","
L"\"Time\": \"%s\","
L"\"Channel\": \"%s\","
L"\"Level\": \"%s\","
Expand All @@ -595,6 +597,7 @@
formattedEvent = Utility::FormatString(
logFmt.c_str(),
pLogEntry->source.c_str(),
pLogEntry->eventSource.c_str(),
pLogEntry->eventTime.c_str(),
pLogEntry->eventChannel.c_str(),
pLogEntry->eventLevel.c_str(),
Expand Down Expand Up @@ -829,6 +832,7 @@
if (Utility::CompareWStrings(eventField, L"TimeStamp")) oss << pLogEntry->eventTime;
if (Utility::CompareWStrings(eventField, L"Severity")) oss << pLogEntry->eventLevel;
if (Utility::CompareWStrings(eventField, L"Source")) oss << pLogEntry->source;
if (Utility::CompareWStrings(eventField, L"EventSource")) oss << pLogEntry->eventSource;
if (Utility::CompareWStrings(eventField, L"EventID")) oss << pLogEntry->eventId;
if (Utility::CompareWStrings(eventField, L"Message")) oss << pLogEntry->eventMessage;

Expand Down
1 change: 1 addition & 0 deletions LogMonitor/src/LogMonitor/EventMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class EventMonitor final

struct EventLogEntry {
std::wstring source;
std::wstring eventSource;
std::wstring eventTime;
std::wstring eventChannel;
std::wstring eventLevel;
Expand Down
Loading