Skip to content

Commit 7a509cc

Browse files
authored
Merge pull request #167 from Icinga:fix/split_eventlog_messages_larger_then_30000_chars
Fix: Fixes error while writing EventLog entries with too large message size In rare cases it can happen that the EventLog writer will throw an error in case the message size for EventLog entries is too large. This mostly happens in case the debug mode is enabled which is writing plenty of content into the EventLog. This fix will now split such message into multiple messages to resolve the issue and keeping the data.
2 parents 054459c + 4c628c7 commit 7a509cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
4343
* [#159](https://github.com/Icinga/icinga-powershell-framework/pull/159) Fixes crash during update of the Icinga Framework, caused by the newly introduced experimental feature for code caching
4444
* [#165](https://github.com/Icinga/icinga-powershell-framework/pull/165) Fixes fetching for Icinga Agent certificate for REST-Api daemon on upper/lower case hostname mismatch
4545
* [#166](https://github.com/Icinga/icinga-powershell-framework/pull/166) Fixes fetching of Icinga Agent MSI packages by correctly comparing versions to ensure we always use the latest version and fixes `release` usage for local/network drive sources
46+
* [#167](https://github.com/Icinga/icinga-powershell-framework/pull/167) Fixes error while writing EventLog entries with too large message size
4647

4748
## 1.2.0 (2020-08-28)
4849

lib/core/logging/Write-IcingaEventMessage.psm1

+19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ function Write-IcingaEventMessage()
5151
return;
5252
}
5353

54+
[int]$MaxEventLogMessageSize = 30000;
55+
56+
if ($EventLogMessage.Length -ge $MaxEventLogMessageSize) {
57+
while ($EventLogMessage.Length -ge $MaxEventLogMessageSize) {
58+
$CutMessage = $EventLogMessage.Substring(0, $MaxEventLogMessageSize);
59+
Write-EventLog -LogName Application `
60+
-Source 'Icinga for Windows' `
61+
-EntryType $EntryType `
62+
-EventId $EventId `
63+
-Message $CutMessage;
64+
65+
$EventLogMessage = $EventLogMessage.Substring($MaxEventLogMessageSize, $EventLogMessage.Length - $MaxEventLogMessageSize);
66+
}
67+
}
68+
69+
if ([string]::IsNullOrEmpty($EventLogMessage)) {
70+
return;
71+
}
72+
5473
Write-EventLog -LogName Application `
5574
-Source 'Icinga for Windows' `
5675
-EntryType $EntryType `

0 commit comments

Comments
 (0)