This is an automated email from the ASF dual-hosted git repository. freeandnil pushed a commit to branch Feature/RemoteSysLogAppender-NewLineHandling in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
commit 68ef2712eee794df725068cf0a52146bb391a821 Author: Jan Friedrich <[email protected]> AuthorDate: Sun Dec 7 22:04:06 2025 +0100 updated documentation for new newline handling #274 --- src/changelog/3.2.1/274-newline-handling.xml | 12 ++++ .../appenders/remotesyslogappender.adoc | 78 ++++++++++++++++------ 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/changelog/3.2.1/274-newline-handling.xml b/src/changelog/3.2.1/274-newline-handling.xml new file mode 100644 index 00000000..c8e7196f --- /dev/null +++ b/src/changelog/3.2.1/274-newline-handling.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="https://logging.apache.org/xml/ns" + xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" + type="changed"> + <issue id="274" link="https://github.com/apache/logging-log4net/issue/274"/> + <issue id="276" link="https://github.com/apache/logging-log4net/pull/276"/> + <description format="asciidoc"> +https://logging.apache.org/log4net/manual/configuration/appenders/remotesyslogappender.html#newlinehandling[Newline handling] changed +(by @FreeAndNil in https://github.com/apache/logging-log4net/pull/276[#276]) + </description> +</entry> \ No newline at end of file diff --git a/src/site/antora/modules/ROOT/pages/manual/configuration/appenders/remotesyslogappender.adoc b/src/site/antora/modules/ROOT/pages/manual/configuration/appenders/remotesyslogappender.adoc index 141e8952..0a301b04 100644 --- a/src/site/antora/modules/ROOT/pages/manual/configuration/appenders/remotesyslogappender.adoc +++ b/src/site/antora/modules/ROOT/pages/manual/configuration/appenders/remotesyslogappender.adoc @@ -60,35 +60,69 @@ You can also specify: [#newlinehandling] == Newline handling -If your log message contains multiple lines, it will be logged as multiple separate syslog entries instead of a single multiline message. +Newline handling changed in version 3.3.0. -This might lead to confusion when analyzing logs because related lines could appear interleaved with logs from other sources. +Before version 3.3.0, newline characters (`\r` or `\n`) were always treated as line breaks. +Messages containing newlines were therefore split into multiple syslog entries. -Example: +Starting with 3.3.0, newline handling is configurable through the `NewLineHandling` option. +The new default is `Escape`. + +The available modes are: + +`Escape` (default since 3.3.0):: + Newlines are replaced with the escaped representations `\r` → "\\r" and `\n` → "\\n`. + The message is sent as a single syslog entry. + +`Split` (default before 3.3.0):: + The message is split at each newline into multiple syslog entries. + Combined sequences (\r\n or \n\r) count as a single break. + This matches the behaviour in versions before 3.3.0. + +`Keep`:: + Newlines are preserved as-is in the message content. + Many syslog servers can process entries containing embedded newlines, but server support varies. + +=== Example: Escape + +Input: [source,csharp] ----- -try -{ - throw new InvalidTimeZoneException(); -} -catch (InvalidTimeZoneException e) -{ - logger.Error(e, "setting daylight saving time failed") -} ----- +logger.Error("A\nB\r\nC"); -Output (with intermixed messages): +Output (one syslog entry): [source,log] ----- -12/21/2024 14:07:41.508 [main] ERROR log4net.Tests - setting daylight saving time failed -Exception of type 'System.InvalidTimeZoneException' was thrown. -12/21/2024 14:07:41.511 [worker] WARN log4net.Tests - some unrelated log message - at log4net.Tests.Appender.RemoteSyslogAppenderTest.LineBreakTest() - at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) - at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) ----- +... ERROR ... - A\nB\rC + +=== Example: Split + +Input: + +[source,csharp] +logger.Error("A\nB\r\nC"); + +Output (three syslog entries, unrelated messages may interleave): + +[source,log] +... ERROR ... - A +... ERROR ... - B +... INFO ... - something unrelated +... ERROR ... - C + +=== Example: Keep + +Input: + +[source,csharp] +logger.Error("A\nB\r\nC"); + +Output (one syslog entry, with embedded newlines): + +[source,log] +... ERROR ... - A +B +C [#sizelimits] == Size limits
