private static void Main(string[] args)
        {
            // Test that LoggingCircuitBreaker works
            TestMethodThrowingException();
            TestMethodThrowingException();
            if (testMethodCounter != 1)
            {
                Console.Error.WriteLine("LoggingCircuitBreaker aspect does not work.");
                return;
            }
            LoggingCircuitBreaker.Reset();

            // Configure NLog.
            var nlogConfig = new LoggingConfiguration();

            var fileTarget = new FileTarget("file")
            {
                FileName         = "nlog.log",
                KeepFileOpen     = true,
                ConcurrentWrites = false
            };

            nlogConfig.AddTarget(fileTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));

            var consoleTarget = new ConsoleTarget("console");

            nlogConfig.AddTarget(consoleTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));

            LogManager.Configuration = nlogConfig;
            LogManager.EnableLogging();

            TextLoggingBackend backend = new CircuitBreakingLoggingBackend();

            LoggingServices.DefaultBackend = backend;

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");

            // Simulate an error.
            LoggingCircuitBreaker.Break();
            Console.WriteLine("*** ERROR ***   There should be no log lines below.");

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
        protected override bool IsBackendEnabled(LogLevel level)
        {
            if (!LoggingCircuitBreaker.Closed)
            {
                return(false);
            }

            try
            {
                return(base.IsBackendEnabled(level));
            }
            catch (Exception)
            {
                LoggingCircuitBreaker.Break();
                return(false);
            }
        }
 public void OnException([FlowBehavior] out FlowBehavior flowBehavior)
 {
     LoggingCircuitBreaker.Break();
     flowBehavior = FlowBehavior.Return;
 }