fluffynuts commented on code in PR #364:
URL: https://github.com/apache/logging-log4net/pull/364#discussion_r4595811832


##########
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:
   nothing stops this exception object from being null, which means that the 
`.ToString()` can fail, and then the handler will fail too - could probably 
guard with:
   
   ```csharp
   return $"{exception?.GetType()?.FullName ?? "null exception object"}..."
   ```
   but there's probably a neater way; I see that callers generally test for 
null first, so perhaps this isn't a big deal as an internal method - it's just 
a potential trap for later.



##########
src/log4net/NDC.cs:
##########
@@ -239,7 +244,8 @@ public static class NDC
   /// </code>
   /// </example>
   /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/

Review Comment:
   there are a bunch of commented out `[Obsolete]` markers in this file, and 
all the commentary suggests that these methods _should_ be obsolete - so why 
are the decorations commented out?



##########
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:
   I must admit that I'd treat null like an empty array here; I guess neither 
is significantly better than the other.



-- 
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]

Reply via email to