Home > Blockchain >  ReportEvent: Logged messages run all lines together
ReportEvent: Logged messages run all lines together

Time:11-17

I'm noticing that when logging a multi-line message using ReportEvent, it drops all line ends and runs the text together. For example, my MC file may have:

MessageId=
Severity=Informational
SymbolicName=MSG_TEST_MSG
Language=English
Some text
Another line of text.
Last line of text.
.

The message in Event Viewer shows all three lines run together.

If I put \r\n sequences in the text in insertion strings, those line ends do show up correctly in the logged message.

Also, if I use FormatMessageW to generate the text string of the above message, the line ends are correctly included in the text. They seem to be removed only when posting to Event Viewer.

I have not seen ANY reference to the fact that line ends are being dropped anywhere. Any idea? Is this just the way it is?

Thanks.

CodePudding user response:

You have to use %n to force a "hard line break" inside the message.

Source:

%n

Generates a hard line break when it occurs at the end of a line. This can be used with FormatMessage to ensure that the message fits a certain width.

"Why does Format­Message say that %0 terminates the message without a trailing newline? Is it secretly adding newlines?" might also be interesting in this context.

  • Related