FreeAndNil commented on code in PR #364:
URL: https://github.com/apache/logging-log4net/pull/364#discussion_r4606854615
##########
src/log4net/Appender/AppenderSkeleton.cs:
##########
@@ -567,9 +578,22 @@ protected virtual void OnClose()
/// </remarks>
protected virtual void Append(LoggingEvent[] loggingEvents)
{
- foreach (LoggingEvent loggingEvent in loggingEvents.EnsureNotNull())
+ loggingEvents.EnsureNotNull();
Review Comment:
Yes, both would be ok. I kept `EnsureNotNull()` because of consistency with
the other entry points. DoAppend never gives null here, so only a broken
subclass can reach this, and then I prefer it fails loud.
##########
src/log4net/Util/Log4NetAssert.cs:
##########
@@ -114,4 +114,21 @@ public static T EnsureIs<T>(
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool IsFatal(this Exception exception)
=> exception is OutOfMemoryException or StackOverflowException;
+
+ /// <summary>
+ /// Renders <paramref name="exception"/> with its <c>ToString()</c>, or with
the type names when that throws.
+ /// </summary>
+ /// <param name="exception">Exception</param>
+ /// <returns>The exception's text, or a fallback naming its type and the
type it threw</returns>
+ internal static string ToStringSafe(this Exception exception)
+ {
+ try
+ {
+ return exception.ToString();
+ }
+ catch (Exception e) when (!e.IsFatal())
+ {
+ return $"{exception.GetType().FullName}: <Exception while rendering
exception: {e.GetType().FullName}>";
Review Comment:
In theory you are right. But we have nullable warnings as errors, so a
maybe-null argument does not compile. And all callers check before or give a
caught exception. It is internal, so I would leave it like it is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]