Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="isSingleton">if set to <c>true</c> [is singleton].</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        internal RollbarLogger(bool isSingleton, IRollbarConfig rollbarConfig)
        {
            if (!TelemetryCollector.Instance.IsAutocollecting)
            {
                TelemetryCollector.Instance.StartAutocollection();
            }

            this.IsSingleton = isSingleton;

            if (rollbarConfig != null)
            {
                ValidateConfiguration(rollbarConfig);
                this._config = new RollbarConfig(this).Reconfigure(rollbarConfig);
            }
            else
            {
                this._config = new RollbarConfig(this);
            }

            // let's figure out where to keep the local payloads store:
            StoreContext.RollbarStoreDbFullName = ((RollbarConfig)this._config).GetLocalPayloadStoreFullPathName();

            // let's init proper Rollbar client:
            var rollbarClient = new RollbarClient(this);

            // let's init the corresponding queue and register it:
            this._payloadQueue = new PayloadQueue(this, rollbarClient);
            RollbarQueueController.Instance.Register(this._payloadQueue);
        }
Beispiel #2
0
        /// <summary>
        /// Tries the posting.
        /// </summary>
        /// <param name="payloadRecord">The payload record.</param>
        /// <returns>RollbarResponse.</returns>
        private RollbarResponse TryPosting(PayloadRecord payloadRecord)
        {
            //Payload payload = JsonConvert.DeserializeObject<Payload>(payloadRecord.PayloadJson);
            //IRollbarConfig config = payload.Data.Notifier.Configuration;
            IRollbarConfig config        = JsonConvert.DeserializeObject <RollbarConfig>(payloadRecord.ConfigJson);
            RollbarClient  rollbarClient = new RollbarClient(config);

            try
            {
                RollbarResponse response =
                    rollbarClient.PostAsJson(config.EndPoint, config.AccessToken, payloadRecord.PayloadJson);
                return(response);
            }
            catch (System.Exception ex)
            {
                this.OnRollbarEvent(
                    new CommunicationErrorEventArgs(null, payloadRecord.PayloadJson, ex, 0)
                    );

                RollbarErrorUtility.Report(
                    null,
                    payloadRecord,
                    InternalRollbarError.PersistentPayloadRecordRepostError,
                    "While trying to report a stored payload...",
                    ex,
                    null
                    );

                return(null);
            }
        }
Beispiel #3
0
        internal RollbarLogger(bool isSingleton)
        {
            try
            {
                this._nativeTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (InvalidOperationException ex)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                // it could be a valid case in some environments:
                this._nativeTaskScheduler = null;
            }

            if (!TelemetryCollector.Instance.IsAutocollecting)
            {
                TelemetryCollector.Instance.StartAutocollection();
            }

            this.IsSingleton = isSingleton;
            this._config     = new RollbarConfig(this);
            var rollbarClient = new RollbarClient(
                this._config
                , RollbarQueueController.Instance.ProvideHttpClient(this._config.ProxyAddress, this._config.ProxyUsername, this._config.ProxyPassword)
                );
            this._payloadQueue = new PayloadQueue(this, rollbarClient);
            RollbarQueueController.Instance.Register(this._payloadQueue);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger"/> class.
        /// </summary>
        /// <param name="isSingleton">if set to <c>true</c> [is singleton].</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        internal RollbarLogger(bool isSingleton, IRollbarConfig rollbarConfig)
        {
            if (!TelemetryCollector.Instance.IsAutocollecting)
            {
                TelemetryCollector.Instance.StartAutocollection();
            }

            this.IsSingleton = isSingleton;

            if (rollbarConfig != null)
            {
                this._config = rollbarConfig;
            }
            else
            {
                this._config = new RollbarConfig(this);
            }

            var rollbarClient = new RollbarClient(
                this._config
                , RollbarQueueController.Instance.ProvideHttpClient(
                    this._config.ProxyAddress,
                    this._config.ProxyUsername,
                    this._config.ProxyPassword
                    )
                );

            this._payloadQueue = new PayloadQueue(this, rollbarClient);
            RollbarQueueController.Instance.Register(this._payloadQueue);
        }
        public PayloadQueue(RollbarLogger logger, RollbarClient client)
        {
            Assumption.AssertNotNull(logger, nameof(logger));
            Assumption.AssertNotNull(client, nameof(client));
            Assumption.AssertTrue(object.ReferenceEquals(logger.Config, client.Config), nameof(client.Config));

            this._logger   = logger;
            this._syncLock = new object();
            this._queue    = new Queue <Payload>();
            this._client   = client;
        }
Beispiel #6
0
        public void UpdateClient(RollbarClient client)
        {
            if (this._client == client)
            {
                return;
            }

            lock (this._syncLock)
            {
                this._client = client;
            }
        }
        private RollbarResponse Process(Payload payload, RollbarConfig config)
        {
            var client = new RollbarClient(config);

            IEnumerable <string> safeScrubFields = config.ScrubFields;

            RollbarResponse response = null;
            int             retries  = 3;

            while (retries > 0)
            {
                try
                {
                    response = client.PostAsJson(payload, safeScrubFields);
                }
                catch (WebException ex)
                {
                    retries--;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(config, payload, ex, retries)
                        );
                    continue;
                }
                catch (ArgumentNullException ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(config, payload, ex, retries)
                        );
                    continue;
                }
                catch (System.Exception ex)
                {
                    retries = 0;
                    this.OnRollbarEvent(
                        new CommunicationErrorEventArgs(config, payload, ex, retries)
                        );
                    continue;
                }
                retries = 0;
            }

            if (response != null)
            {
                this.OnRollbarEvent(
                    new CommunicationEventArgs(config, payload, response)
                    );
            }

            return(response);
        }
Beispiel #8
0
        /// <summary>
        /// Reconfigures this object similar to the specified one.
        /// </summary>
        /// <param name="likeMe">The pre-configured instance to be cloned in terms of its configuration/settings.</param>
        /// <returns>
        /// Reconfigured instance.
        /// </returns>
        public override RollbarConfig Reconfigure(IRollbarConfig likeMe)
        {
            base.Reconfigure(likeMe);

            if (this.Logger != null && this.Logger.Queue != null)
            {
                var rollbarClient = new RollbarClient(this.Logger);
                // reset the queue to use the new RollbarClient:
                this.Logger.Queue.Flush();
                this.Logger.Queue.UpdateClient(rollbarClient);
            }

            return(this);
        }
        /// <summary>
        /// Reconfigures this object similar to the specified one.
        /// </summary>
        /// <param name="likeMe">The pre-configured instance to be cloned in terms of its configuration/settings.</param>
        /// <returns>
        /// Reconfigured instance.
        /// </returns>
        public override RollbarConfig Reconfigure(IRollbarConfig likeMe)
        {
            base.Reconfigure(likeMe);

            var rollbarClient = new RollbarClient(
                this
                , RollbarQueueController.Instance.ProvideHttpClient(this.ProxyAddress, this.ProxyUsername, this.ProxyPassword)
                );

            if (this.Logger != null && this.Logger.Queue != null)
            {
                // reset the queue to use the new RollbarClient:
                this.Logger.Queue.Flush();
                this.Logger.Queue.UpdateClient(rollbarClient);
                this.Logger.Queue.NextDequeueTime = DateTimeOffset.Now;
            }

            return(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarLogger" /> class.
        /// </summary>
        /// <param name="isSingleton">if set to <c>true</c> [is singleton].</param>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        internal RollbarLogger(bool isSingleton, IRollbarConfig rollbarConfig)
        {
            if (!TelemetryCollector.Instance.IsAutocollecting)
            {
                TelemetryCollector.Instance.StartAutocollection();
            }

            this.IsSingleton = isSingleton;

            if (rollbarConfig != null)
            {
                this._config = new RollbarConfig(this).Reconfigure(rollbarConfig);
            }
            else
            {
                this._config = new RollbarConfig(this);
            }

            var rollbarClient = new RollbarClient(this);

            this._payloadQueue = new PayloadQueue(this, rollbarClient);
            RollbarQueueController.Instance.Register(this._payloadQueue);
        }