Exemplo n.º 1
0
 public void ReportException()
 {
     using (IRollbar logger = this.ProvideDisposableRollbar())
     {
         try
         {
             this.ExpectedCommunicationEventsTotal++;
             logger.AsBlockingLogger(defaultRollbarTimeout).Error(new System.Exception("test exception"));
         }
         catch
         {
             Assert.Fail("the execution should not reach here!");
         }
     }
 }
Exemplo n.º 2
0
 public void ReportMessage()
 {
     using (IRollbar logger = this.ProvideDisposableRollbar())
     {
         try
         {
             this.IncrementCount <CommunicationEventArgs>();
             logger.AsBlockingLogger(defaultRollbarTimeout).Log(ErrorLevel.Error, "test message");
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex);
             Assert.Fail("should never reach here!");
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the proper.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="blockingLoggingTimeout">The blocking logging timeout.</param>
        /// <returns>ILogger.</returns>
        public static ILogger CreateProper(
            IRollbarLoggerConfig?config     = null,
            TimeSpan?blockingLoggingTimeout = null
            )
        {
            IRollbar rollbar = RollbarFactory.CreateNew(config);

            if (blockingLoggingTimeout.HasValue)
            {
                return(rollbar.AsBlockingLogger(blockingLoggingTimeout.Value));
            }
            else
            {
                return(rollbar.Logger);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the proper.
        /// </summary>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="rollbarBlockingLoggingTimeout">The rollbar blocking logging timeout.</param>
        public static ILogger CreateProper(
            IRollbarConfig rollbarConfig,
            TimeSpan?rollbarBlockingLoggingTimeout
            )
        {
            IRollbar rollbar = RollbarFactory.CreateNew().Configure(rollbarConfig);

            if (rollbarBlockingLoggingTimeout.HasValue)
            {
                return(rollbar.AsBlockingLogger(rollbarBlockingLoggingTimeout.Value));
            }
            else
            {
                return(rollbar.Logger);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the proper.
        /// </summary>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="rollbarBlockingLoggingTimeout">The rollbar blocking logging timeout.</param>
        /// <param name="rollbarAsyncLogger">The rollbar asynchronous logger.</param>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        public static void CreateProper(
            IRollbarConfig rollbarConfig,
            TimeSpan?rollbarBlockingLoggingTimeout,
            out IAsyncLogger rollbarAsyncLogger,
            out ILogger rollbarLogger
            )
        {
            IRollbar rollbar = RollbarFactory.CreateNew().Configure(rollbarConfig);

            if (rollbarBlockingLoggingTimeout.HasValue)
            {
                rollbarLogger      = rollbar.AsBlockingLogger(rollbarBlockingLoggingTimeout.Value);
                rollbarAsyncLogger = null;
            }
            else
            {
                rollbarLogger      = null;
                rollbarAsyncLogger = rollbar;
            }
        }
Exemplo n.º 6
0
        public void TimeoutExceptionAggregatesMisconfigurationDetails()
        {
            RollbarConfig badConfig = new RollbarConfig("MISCONFIGURED_TOKEN"); // this is clearly wrong token...

            using (IRollbar logger = RollbarFactory.CreateNew(badConfig))
            {
                try
                {
                    var badData = new Data(new Body("Misconfigured Person data"));
                    badData.Person = new Person();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Log(badData);
                    Assert.Fail("No TimeoutException!");
                }
                catch (TimeoutException ex)
                {
                    Assert.IsNotNull(ex.InnerException);
                    Assert.IsTrue(ex.InnerException is AggregateException);
                    Assert.IsTrue((ex.InnerException as AggregateException).InnerExceptions.Count > 0);
                }
            }
        }
 public void ReportFromCatch()
 {
     try
     {
         var a = 10;
         var b = 0;
         var c = a / b;
     }
     catch (System.Exception ex)
     {
         using IRollbar logger = this.ProvideDisposableRollbar();
         try
         {
             this.IncrementCount <CommunicationEventArgs>();
             logger.AsBlockingLogger(defaultRollbarTimeout).Error(new System.Exception("outer exception", ex));
         }
         catch
         {
             Assert.Fail();
         }
     }
 }
        public void TimeoutExceptionAggregatesMisconfigurationDetails()
        {
            RollbarQueueController.Instance.InternalEvent += Instance_InternalEvent;

            RollbarLoggerConfig badConfig = new RollbarLoggerConfig("MISCONFIGURED_TOKEN"); // this is clearly wrong token...

            using (IRollbar logger = RollbarFactory.CreateNew(badConfig))
            {
                try
                {
                    var badData = new Data(new Body("Misconfigured Person data"));
                    badData.Person = new Person();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Log(badData);
                    Assert.Fail("No TimeoutException!");
                }
                catch (TimeoutException ex)
                {
                    Assert.AreEqual("Posting a payload to the Rollbar API Service timed-out", ex.Message);
                    Assert.IsNotNull(ex.InnerException);
                    Assert.IsTrue(ex.InnerException is AggregateException);
                    Assert.IsTrue((ex.InnerException as AggregateException).InnerExceptions.Count > 0);
                }
            }
        }
Exemplo n.º 9
0
        public void AllowsProxySettingsReconfiguration()
        {
            this.Reset();

            using (IRollbar logger = this.ProvideDisposableRollbar())
            {
                IRollbarConfig initialConfig = logger.Config;

                Assert.AreSame(initialConfig, logger.Config);
                logger.Configure(initialConfig);
                Assert.AreSame(initialConfig, logger.Config);

                int errorCount = 0;
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 1");
                this.IncrementCount <CommunicationEventArgs>();
                Assert.AreEqual(0, errorCount);

                RollbarConfig newConfig = new RollbarConfig("seed");
                newConfig.Reconfigure(initialConfig);
                Assert.AreNotSame(initialConfig, newConfig);
                logger.Configure(newConfig);
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 2");
                this.IncrementCount <CommunicationEventArgs>();
                Assert.AreEqual(0, errorCount);

                newConfig.ProxyAddress  = "www.fakeproxy.com";
                newConfig.ProxyUsername = "******";
                newConfig.ProxyPassword = "******";
                logger.Configure(newConfig);
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsFalse(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings will cause a timeout exception here:
                    this.IncrementCount <CommunicationErrorEventArgs>();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 3 with fake proxy");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);

                newConfig.ProxyAddress  = null;
                newConfig.ProxyUsername = null;
                newConfig.ProxyPassword = null;
                logger.Configure(newConfig);
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyAddress));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyUsername));
                Assert.IsTrue(string.IsNullOrEmpty(logger.Config.ProxyPassword));
                try
                {
                    // the fake proxy settings are gone, so, next call is expected to succeed:
                    this.IncrementCount <CommunicationEventArgs>();
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(15)).Info("test 4");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);
            }
        }