Exception Logging Filter - CSharp Custom Type

CSharp examples for Custom Type:Exception

Description

Exception Logging Filter

Demo Code

using System;//ww  w .  java  2s  .co m
using System.ComponentModel;
class LoggingFilter
{
   static void Main()
   {
      try
      {
         UnreliableMethod();
      }
      catch (Exception e) when (Log(e))
      {
      }
    }
    static void UnreliableMethod()
    {
       throw new Exception("Bang!");
    }
    static bool Log(Exception e)
    {
       Console.WriteLine($"{DateTime.UtcNow}: {e.GetType()} {e.Message}");
       return false;
    }
}

Result


Related Tutorials