Ejemplo n.º 1
0
 public void ReportFromCatch()
 {
     try
     {
         var a = 10;
         var b = 0;
         var c = a / b;
     }
     catch (System.Exception ex)
     {
         using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
         {
             try
             {
                 this.ExpectedCommunicationEventsTotal++;
                 //TODO: implement and add SynchronousPackage around the payload object!!!
                 logger.Error(new System.Exception("outer exception", ex));
             }
             catch
             {
                 Assert.Fail();
             }
         }
     }
 }
        /// <summary>
        /// Provides the disposable rollbar.
        /// </summary>
        /// <returns>IRollbar.</returns>
        protected IRollbar ProvideDisposableRollbar()
        {
            IRollbar rollbar = RollbarFactory.CreateNew(isSingleton: false, rollbarConfig: this.ProvideLiveRollbarConfig());

            this._disposableRollbarInstances.Add(rollbar);
            return(rollbar);
        }
Ejemplo n.º 3
0
        public void LongReportIsAsync()
        {
            const int     maxCallLengthInMillisec = 50;
            TimeSpan      payloadSubmissionDelay  = TimeSpan.FromMilliseconds(3 * maxCallLengthInMillisec);
            RollbarConfig loggerConfig            =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken)
            {
                Environment = RollbarUnitTestSettings.Environment,
            };

            loggerConfig.Transform = delegate { Thread.Sleep(payloadSubmissionDelay); };
            using (IRollbar logger = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    Stopwatch sw = Stopwatch.StartNew();
                    logger.Log(ErrorLevel.Error, "test message");
                    sw.Stop();
                    Assert.IsTrue(sw.ElapsedMilliseconds < maxCallLengthInMillisec);
                    Thread.Sleep(payloadSubmissionDelay);
                }
                catch
                {
                    Assert.Fail("should never get here!");
                }
            }
        }
        public void FaultyTruncateTest()
        {
            this.Reset();

            RollbarLoggerConfig config = this.ProvideLiveRollbarConfig() as RollbarLoggerConfig;
            RollbarPayloadManipulationOptions payloadManipulationOptions = new RollbarPayloadManipulationOptions();

            payloadManipulationOptions.Truncate = delegate(Payload payload)
            {
                throw new Exception("Buggy truncate delegate!");
            };
            config.RollbarPayloadManipulationOptions.Reconfigure(payloadManipulationOptions);

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);

                rollbar.Critical("This message's Truncate will fail!");

                this.VerifyInstanceOperational(rollbar);
                // one more extra sanity check:
                Assert.AreEqual(0, RollbarQueueController.Instance.GetTotalPayloadCount());
            }

            this.Reset();
        }
        public void ImplementsIDisposable()
        {
            using IRollbar logger = this.ProvideDisposableRollbar();
            IDisposable disposable = logger as IDisposable;

            Assert.IsNotNull(disposable);
        }
        public void ExceptionWhileTransformingPayloadAsync()
        {
            this._transformException = false;

            RollbarConfig loggerConfig =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken)
            {
                Environment = RollbarUnitTestSettings.Environment,
            };

            loggerConfig.Transform = delegate { throw new NullReferenceException(); };
            IRollbar logger = RollbarFactory.CreateNew().Configure(loggerConfig);

            logger.InternalEvent += Logger_InternalEvent;

            try
            {
                logger.Log(ErrorLevel.Error, "test message");
            }
            catch
            {
                Assert.IsTrue(false);
            }

            this._signal.Wait();

            Assert.IsTrue(this._transformException);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarBlazorClient"/> class.
        /// </summary>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        /// <param name="httpClient">The HTTP client.</param>
        public RollbarBlazorClient(IRollbar rollbarLogger, HttpClient httpClient)
            : base(rollbarLogger)
        {
            Assumption.AssertNotNull(httpClient, nameof(httpClient));

            this.Set(httpClient);
        }
Ejemplo n.º 8
0
        public void TransmitConfigOptionWorks()
        {
            this.Reset();

            RollbarConfig config = this.ProvideLiveRollbarConfig() as RollbarConfig;

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical("Transmission is expected to happen!");
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to happen!");

                config.Transmit = false;
                rollbar.Configure(config);
                this.IncrementCount <TransmissionOmittedEventArgs>();
                rollbar.Critical("Transmission is expected to be omitted!");
                this.IncrementCount <TransmissionOmittedEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to be omitted!");

                config.Transmit = true;
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical("Transmission is expected to happen!");
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3)).Critical("Transmission is expected to happen!");
            }
        }
Ejemplo n.º 9
0
        public void AllowsProxySettingsReconfiguration()
        {
            using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
            {
                Assert.AreNotSame(this._loggerConfig, logger.Config);
                logger.Configure(this._loggerConfig);
                Assert.AreNotSame(this._loggerConfig, logger.Config);

                int errorCount = 0;
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 1");
                this.ExpectedCommunicationEventsTotal++;
                Assert.AreEqual(0, errorCount);

                RollbarConfig newConfig = new RollbarConfig("seed");
                newConfig.Reconfigure(this._loggerConfig);
                Assert.AreNotSame(this._loggerConfig, newConfig);
                logger.Configure(newConfig);
                logger.AsBlockingLogger(TimeSpan.FromSeconds(3)).Info("test 2");
                this.ExpectedCommunicationEventsTotal++;
                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.ExpectedCommunicationErrorsTotal++;
                    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.ExpectedCommunicationEventsTotal++;
                    logger.AsBlockingLogger(TimeSpan.FromSeconds(15)).Info("test 4");
                }
                catch
                {
                    errorCount++;
                }
                Assert.AreEqual(1, errorCount);
            }
        }
Ejemplo n.º 10
0
        public void ExceptionWhileTransformingPayloadAsync()
        {
            this._transformException = false;

            RollbarConfig loggerConfig =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken)
            {
                Environment = RollbarUnitTestSettings.Environment,
            };

            loggerConfig.Transform = delegate { throw new NullReferenceException(); };
            using (IRollbar logger = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                logger.InternalEvent += Logger_InternalEvent;

                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    logger.Log(ErrorLevel.Error, "test message");
                }
                catch
                {
                    logger.InternalEvent -= Logger_InternalEvent;
                    Assert.Fail("should never get here!");
                }

                this._signal.Wait();
                logger.InternalEvent -= Logger_InternalEvent;

                Assert.IsTrue(this._transformException);
            }
        }
        /// <summary>
        /// Prevents a default instance of the <see cref="RollbarLogger" /> class from being created.
        /// </summary>
        private RollbarLogger()
        {
            this._name = string.Empty;

            this._rollbarOptions = new RollbarOptions();

            this._rollbar = RollbarFactory.CreateNew(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle" /> class.
 /// </summary>
 /// <param name="rollbarLogger">The rollbar logger.</param>
 /// <param name="payloadObject">The payload object.</param>
 /// <param name="level">The level.</param>
 public PayloadBundle(
     IRollbar rollbarLogger,
     object payloadObject,
     ErrorLevel level
     )
     : this(rollbarLogger, payloadObject, level, null, null, null)
 {
 }
Ejemplo n.º 13
0
 public void ImplementsIDisposable()
 {
     using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
     {
         IDisposable disposable = logger as IDisposable;
         Assert.IsNotNull(disposable);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle" /> class.
 /// </summary>
 /// <param name="rollbarLogger">The rollbar logger.</param>
 /// <param name="payloadPackage">The payload package.</param>
 /// <param name="level">The level.</param>
 public PayloadBundle(
     IRollbar rollbarLogger,
     IRollbarPackage payloadPackage,
     ErrorLevel level
     )
     : this(rollbarLogger, payloadPackage, level, null, null, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle" /> class.
 /// </summary>
 /// <param name="rollbarLogger">The rollbar logger.</param>
 /// <param name="payloadObject">The payload object.</param>
 /// <param name="level">The level.</param>
 /// <param name="custom">The custom.</param>
 public PayloadBundle(
     IRollbar rollbarLogger,
     object payloadObject,
     ErrorLevel level,
     IDictionary <string, object?>?custom
     )
     : this(rollbarLogger, payloadObject, level, custom, null, null)
 {
 }
        public void SetupFixture()
        {
            RollbarUnitTestEnvironmentUtil.SetupLiveTestRollbarInfrastructure();

            RollbarQueueController.Instance.FlushQueues();
            //RollbarQueueController.Instance.InternalEvent += Instance_InternalEvent;

            _logger = RollbarFactory.CreateNew().Configure(RollbarInfrastructure.Instance.Config.RollbarLoggerConfig);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarClientBase"/> class.
        /// </summary>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        protected RollbarClientBase(IRollbar rollbarLogger)
            : this(rollbarLogger.Config)
        {
            Assumption.AssertNotNull(rollbarLogger, nameof(rollbarLogger));

            this._rollbarLogger = rollbarLogger;

            this._payloadTruncator = new(rollbarLogger);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle" /> class.
 /// </summary>
 /// <param name="rollbarLogger">The rollbar logger.</param>
 /// <param name="payloadObject">The payload object.</param>
 /// <param name="level">The level.</param>
 /// <param name="timeoutAt">The timeout at.</param>
 /// <param name="signal">The signal.</param>
 public PayloadBundle(
     IRollbar rollbarLogger,
     object payloadObject,
     ErrorLevel level,
     DateTime?timeoutAt,
     SemaphoreSlim?signal
     )
     : this(rollbarLogger, payloadObject, level, null, timeoutAt, signal)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle" /> class.
 /// </summary>
 /// <param name="rollbarLogger">The rollbar logger.</param>
 /// <param name="payloadPackage">The payload package.</param>
 /// <param name="level">The level.</param>
 /// <param name="timeoutAt">The timeout at.</param>
 /// <param name="signal">The signal.</param>
 public PayloadBundle(
     IRollbar rollbarLogger,
     IRollbarPackage payloadPackage,
     ErrorLevel level,
     DateTime?timeoutAt,
     SemaphoreSlim?signal
     )
     : this(rollbarLogger, payloadPackage, level, null, timeoutAt, signal)
 {
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="rollbarOptions">The options.</param>
        public RollbarLogger(string name
                             , IRollbarConfig rollbarConfig
                             , RollbarOptions rollbarOptions = default
                             )
        {
            this._name           = name;
            this._rollbarOptions = rollbarOptions ?? new RollbarOptions();

            this._rollbar = RollbarFactory.CreateNew(rollbarConfig);
        }
        public void _VerifyInstanceOperationalTest()
        {
            // this test more about verifying if the test harness itself works well:

            this.ClearAllRollbarInternalEvents();

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                this.VerifyInstanceOperational(rollbar);
            }
        }
        protected void VerifyInstanceOperational(IRollbar rollbar)
        {
            MakeSureAllThePayloadsProcessed();

            //Assert.IsTrue(0 == RollbarQueueController.Instance.GetTotalPayloadCount(), "Making sure all the queues are clear...");
            int initialCommunicationEventsCount = this.ActualComunicationEventsCount;

            this.ExpectedCommunicationEventsTotal++;
            rollbar.AsBlockingLogger(defaultRollbarTimeout).Critical("Making sure Rollbar.NET is operational...");
            Assert.AreEqual(this.ActualComunicationEventsCount, initialCommunicationEventsCount + 1, "Confirming Rollbar.NET is operational...");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        /// <param name="rollbarOptions">The options.</param>
        /// <param name="httpContextAccessor">The HTTP context accessor.</param>
        public RollbarLogger(string name
                             , IRollbarConfig rollbarConfig
                             , RollbarOptions rollbarOptions
                             , IHttpContextAccessor httpContextAccessor
                             )
        {
            this._name                = name;
            this._rollbarOptions      = rollbarOptions;
            this._httpContextAccessor = httpContextAccessor;

            this._rollbar = RollbarFactory.CreateNew(false).Configure(rollbarConfig);
        }
Ejemplo n.º 24
0
        public void SetupFixture()
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            RollbarConfig loggerConfig =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken)
            {
                Environment = RollbarUnitTestSettings.Environment,
            };

            _logger = RollbarFactory.CreateNew().Configure(loggerConfig);
        }
 public void ReportException()
 {
     using IRollbar logger = this.ProvideDisposableRollbar();
     try
     {
         this.IncrementCount <CommunicationEventArgs>();
         logger.AsBlockingLogger(defaultRollbarTimeout).Error(new System.Exception("test exception"));
     }
     catch
     {
         Assert.Fail("the execution should not reach here!");
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLoggerConfig"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        internal RollbarLoggerConfig(IRollbar logger)
        {
            this._logger = logger;

            this.SetDefaults();

            // initialize based on application configuration file (if any):
            var configLoader = new RollbarConfigurationLoader();
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig();

            configLoader.Load(config);
            this.Reconfigure(config.RollbarLoggerConfig);
        }
 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!");
     }
 }
Ejemplo n.º 28
0
        public void RethrowConfigOptionWorks()
        {
            this.Reset();

            RollbarConfig config = this.ProvideLiveRollbarConfig() as RollbarConfig;

            using (IRollbar rollbar = this.ProvideDisposableRollbar())
            {
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async!"));
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync!"));

                int rethrowCount = 0;
                config.RethrowExceptionsAfterReporting = true;
                rollbar.Configure(config);
                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async with rethrow!"));
                }
                catch
                {
                    rethrowCount++;
                }

                try
                {
                    this.IncrementCount <CommunicationEventArgs>();
                    rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                    .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync with rethrow!"));
                }
                catch
                {
                    rethrowCount++;
                }

                config.RethrowExceptionsAfterReporting = false;
                rollbar.Configure(config);
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged async!"));
                this.IncrementCount <CommunicationEventArgs>();
                rollbar.AsBlockingLogger(TimeSpan.FromSeconds(3))
                .Critical(ExceptionSimulator.GetExceptionWith(5, "Exception logged sync!"));

                Assert.AreEqual(2, rethrowCount, "matching total of rethrows...");
            }
        }
Ejemplo n.º 29
0
 public void ReportMessage()
 {
     using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
     {
         try
         {
             logger.Log(ErrorLevel.Error, "test message");
         }
         catch
         {
             Assert.IsTrue(false);
         }
     }
 }
Ejemplo n.º 30
0
 public void ReportException()
 {
     using (IRollbar logger = RollbarFactory.CreateNew().Configure(this._loggerConfig))
     {
         try
         {
             logger.Error(new System.Exception("test exception"));
         }
         catch
         {
             Assert.IsTrue(false);
         }
     }
 }