dpsenner commented on a change in pull request #43: Enhance the filter to 
support filter the exception type name.
URL: https://github.com/apache/logging-log4net/pull/43#discussion_r243731610
 
 

 ##########
 File path: src/Filter/ExceptionTypeFilter.cs
 ##########
 @@ -0,0 +1,54 @@
+using log4net.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace log4net.Filter
+{
+    public class ExceptionTypeFilter : FilterSkeleton
+    {
+        public ExceptionTypeFilter()
+        {
+            this.AcceptOnMatch = true;
+        }
+
+        /// <summary>
+        /// Set the exception type name to filter
+        /// </summary>
+        public string ExceptionTypeName { get; set; }
+
+        /// <summary>
+        /// <see cref="FilterDecision.Accept"/> when matching <see 
cref="ExceptionTypeName"/>
+        /// Default value is true.
+        /// </summary>
+        public bool AcceptOnMatch { get; set; }
+
+        public override FilterDecision Decide(LoggingEvent loggingEvent)
+        {
+            var myExceptionType = Type.GetType(this.ExceptionTypeName, false);
+
+            if (this.ExceptionTypeName != null
+                && myExceptionType != null
+                && loggingEvent.ExceptionObject != null)
+            {
+
+                var myIsMatched = 
myExceptionType.IsInstanceOfType(loggingEvent.ExceptionObject);
+
+                if (this.AcceptOnMatch)
 
 Review comment:
   Swapping the comparison logic greatly improves the readability of what this 
filter actually does:
   
   ```csharp
   if (isMatch)
   {
      if (AcceptOnMatch)
      {
         return FilterDecision.Accept;
      }
      else
      {
         return FilterDecision.Deny;
      }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to