This is an automated email from the ASF dual-hosted git repository. FreeAndNil pushed a commit to branch Feature/318-telnet-default in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
commit b26e94d5ae1a1ed69968ecc8919c79cf92625121 Author: Jan Friedrich <[email protected]> AuthorDate: Fri Sep 4 09:01:23 2026 +0200 share one RecordingErrorHandler across the appender tests Three copies, two identical and one collecting into a joined string instead of a list. Now one internal helper beside SimpleTelnetClient and UdpMock, exposing Messages; the ANSI test asserts on that instead of its own Message property. --- .../Appender/AnsiColorTerminalAppenderTest.cs | 18 +-------- .../Appender/Internal/RecordingErrorHandler.cs | 44 ++++++++++++++++++++++ .../Appender/RemoteSyslogAppenderTest.cs | 16 -------- src/log4net.Tests/Appender/SmtpAppenderTest.cs | 18 +-------- 4 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/log4net.Tests/Appender/AnsiColorTerminalAppenderTest.cs b/src/log4net.Tests/Appender/AnsiColorTerminalAppenderTest.cs index 222dce26..36806f03 100644 --- a/src/log4net.Tests/Appender/AnsiColorTerminalAppenderTest.cs +++ b/src/log4net.Tests/Appender/AnsiColorTerminalAppenderTest.cs @@ -22,6 +22,7 @@ using log4net.Appender; using log4net.Core; +using log4net.Tests.Appender.Internal; using log4net.Layout; using NUnit.Framework; @@ -82,23 +83,8 @@ public void TheResetCodesGoBeforeATrailingLineBreak(string message, string expec Console.SetOut(previous); } - Assert.That(errorHandler.Message, Is.Empty, "the event must not be dropped"); + Assert.That(errorHandler.Messages, Is.Empty, "the event must not be dropped"); Assert.That(captured.ToString(), Is.EqualTo(expected)); } - /// <summary>Collects what the appender reports, so a dropped event is visible.</summary> - private sealed class RecordingErrorHandler : IErrorHandler - { - /// <summary>Everything reported so far.</summary> - internal string Message { get; private set; } = string.Empty; - - /// <inheritdoc/> - public void Error(string message) => Message += message + '\n'; - - /// <inheritdoc/> - public void Error(string message, Exception e) => Message += message + '\n'; - - /// <inheritdoc/> - public void Error(string message, Exception? e, ErrorCode errorCode) => Message += message + '\n'; - } } diff --git a/src/log4net.Tests/Appender/Internal/RecordingErrorHandler.cs b/src/log4net.Tests/Appender/Internal/RecordingErrorHandler.cs new file mode 100644 index 00000000..d851b586 --- /dev/null +++ b/src/log4net.Tests/Appender/Internal/RecordingErrorHandler.cs @@ -0,0 +1,44 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +using System; +using System.Collections.Generic; + +using log4net.Core; + +namespace log4net.Tests.Appender.Internal; + +/// <summary> +/// Collects what an appender reports instead of letting it reach the console, so a test can +/// assert on it and a provoked error adds no noise to the suite output. +/// </summary> +internal sealed class RecordingErrorHandler : IErrorHandler +{ + /// <summary>Reported messages, in the order they were reported.</summary> + internal List<string> Messages { get; } = []; + + /// <inheritdoc/> + public void Error(string message) => Messages.Add(message); + + /// <inheritdoc/> + public void Error(string message, Exception e) => Messages.Add(message); + + /// <inheritdoc/> + public void Error(string message, Exception? e, ErrorCode errorCode) => Messages.Add(message); +} diff --git a/src/log4net.Tests/Appender/RemoteSyslogAppenderTest.cs b/src/log4net.Tests/Appender/RemoteSyslogAppenderTest.cs index 149d191b..9eb299a2 100644 --- a/src/log4net.Tests/Appender/RemoteSyslogAppenderTest.cs +++ b/src/log4net.Tests/Appender/RemoteSyslogAppenderTest.cs @@ -51,22 +51,6 @@ private sealed class RemoteAppender : RemoteSyslogAppender internal System.Net.Sockets.UdpClient? InheritedClient => Client; } - /// <summary>Collects reported errors instead of letting them reach the console.</summary> - private sealed class RecordingErrorHandler : IErrorHandler - { - /// <summary>Reported messages.</summary> - internal List<string> Messages { get; } = []; - - /// <inheritdoc/> - public void Error(string message, Exception? e, ErrorCode errorCode) => Messages.Add(message); - - /// <inheritdoc/> - public void Error(string message, Exception e) => Messages.Add(message); - - /// <inheritdoc/> - public void Error(string message) => Messages.Add(message); - } - private const int FlushTimeoutMillis = 30_000; /// <summary> diff --git a/src/log4net.Tests/Appender/SmtpAppenderTest.cs b/src/log4net.Tests/Appender/SmtpAppenderTest.cs index 259cfd9c..3489567a 100644 --- a/src/log4net.Tests/Appender/SmtpAppenderTest.cs +++ b/src/log4net.Tests/Appender/SmtpAppenderTest.cs @@ -18,7 +18,6 @@ #endregion using System; -using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Net.Sockets; @@ -27,9 +26,9 @@ using log4net.Appender; using log4net.Config; -using log4net.Core; using log4net.Layout; using log4net.Repository; +using log4net.Tests.Appender.Internal; using log4net.Util; using NUnit.Framework; @@ -120,19 +119,4 @@ public void AnUnresponsiveServerDoesNotStallTheLoggingCall() } } - /// <summary>Collects reported errors instead of letting them reach the console.</summary> - private sealed class RecordingErrorHandler : IErrorHandler - { - /// <summary>Reported messages.</summary> - internal List<string> Messages { get; } = []; - - /// <inheritdoc/> - public void Error(string message, Exception? e, ErrorCode errorCode) => Messages.Add(message); - - /// <inheritdoc/> - public void Error(string message, Exception e) => Messages.Add(message); - - /// <inheritdoc/> - public void Error(string message) => Messages.Add(message); - } }
