Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarEventArgs"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="dataObject">The data object.</param>
        internal RollbarEventArgs(
            RollbarLogger logger,
            object dataObject
            )
        {
            this._logger = logger;

            this.Payload = string.Empty;

            if (dataObject != null)
            {
                string payloadString = dataObject as string;
                if (payloadString != null)
                {
                    this.Payload = payloadString;
                }
                else
                {
                    try
                    {
                        this.Payload = JsonConvert.SerializeObject(dataObject);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex, $"{nameof(RollbarEventArgs)}.{nameof(this.Payload)}");
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarEventArgs"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="dataObject">The data object.</param>
        internal RollbarEventArgs(
            RollbarLogger logger,
            object dataObject
            )
        {
            this._logger = logger;

            this.Payload = string.Empty;

            if (dataObject != null)
            {
                string payloadString = dataObject as string;
                if (payloadString != null)
                {
                    this.Payload = payloadString;
                }
                else
                {
                    try
                    {
                        this.Payload = JsonConvert.SerializeObject(dataObject);
                    }
                    catch (Exception ex)
                    {
                        traceSource.TraceEvent(
                            TraceEventType.Critical,
                            0,
                            $"Exception while serializing payload:{Environment.NewLine}{ex}"
                            );
                    }
                }
            }
        }
Esempio n. 3
0
        public RollbarLoggerBlockingWrapper(RollbarLogger asyncLogger, TimeSpan timeout)
        {
            Assumption.AssertNotNull(asyncLogger, nameof(asyncLogger));

            this._asyncLogger = asyncLogger;
            this._timeout     = timeout;
        }
Esempio n. 4
0
 /// <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(
     RollbarLogger rollbarLogger,
     object payloadObject,
     ErrorLevel level
     )
     : this(rollbarLogger, payloadObject, level, null, null, null)
 {
 }
Esempio n. 5
0
        public PayloadQueue(RollbarLogger logger)
        {
            Assumption.AssertNotNull(logger, nameof(logger));

            this._logger   = logger;
            this._syncLock = new object();
            this._queue    = new Queue <Payload>();
        }
Esempio n. 6
0
 /// <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(
     RollbarLogger rollbarLogger,
     IRollbarPackage payloadPackage,
     ErrorLevel level
     )
     : this(rollbarLogger, payloadPackage, level, null, null, null)
 {
 }
Esempio n. 7
0
 /// <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(
     RollbarLogger rollbarLogger,
     object payloadObject,
     ErrorLevel level,
     IDictionary <string, object> custom
     )
     : this(rollbarLogger, payloadObject, level, custom, null, null)
 {
 }
Esempio n. 8
0
        internal RollbarConfig(RollbarLogger logger)
        {
            this._logger = logger;

            this.SetDefaults();

            // initialize based on application configuration file (if any):
            NetStandard.RollbarConfigUtility.Load(this);
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarClient" /> class.
        /// </summary>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        public RollbarClient(RollbarLogger rollbarLogger)
            : this(rollbarLogger.Config)
        {
            Assumption.AssertNotNull(rollbarLogger, nameof(rollbarLogger));

            this._rollbarLogger = rollbarLogger;

            this._payloadTruncationStrategy = new IterativeTruncationStrategy();
            this._payloadScrubber           = new RollbarPayloadScrubber(this._rollbarLogger.Config.GetFieldsToScrub());
        }
Esempio n. 10
0
 /// <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(
     RollbarLogger rollbarLogger,
     object payloadObject,
     ErrorLevel level,
     DateTime?timeoutAt,
     SemaphoreSlim signal
     )
     : this(rollbarLogger, payloadObject, level, null, timeoutAt, signal)
 {
 }
Esempio n. 11
0
 /// <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(
     RollbarLogger rollbarLogger,
     IRollbarPackage payloadPackage,
     ErrorLevel level,
     DateTime?timeoutAt,
     SemaphoreSlim signal
     )
     : this(rollbarLogger, payloadPackage, level, null, timeoutAt, signal)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommunicationErrorEventArgs"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="error">The error.</param>
 /// <param name="retriesLeft">The retries left.</param>
 internal CommunicationErrorEventArgs(
     RollbarLogger logger,
     Payload payload,
     System.Exception error,
     int retriesLeft
     )
     : base(logger, payload)
 {
     this.Error       = error;
     this.RetriesLeft = retriesLeft;
 }
Esempio n. 13
0
 internal InternalErrorEventArgs(
     RollbarLogger logger,
     Payload payload,
     System.Exception error,
     string details
     )
     : base(logger, payload)
 {
     this.Error   = error;
     this.Details = details;
 }
Esempio n. 14
0
        internal RollbarConfig(RollbarLogger logger)
        {
            this._logger = logger;

            this.SetDefaults();

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

            configLoader.Load(this);
        }
Esempio n. 15
0
 internal InternalErrorEventArgs(
     RollbarLogger logger,
     object dataObject,
     Exception error,
     string details
     )
     : base(logger, dataObject)
 {
     this.Error   = error;
     this.Details = details;
 }
Esempio n. 16
0
 internal RollbarEventArgs(
     RollbarLogger logger,
     object dataObject
     )
 {
     this._logger = logger;
     if (dataObject != null)
     {
         this.Payload = JsonConvert.SerializeObject(dataObject);
     }
 }
Esempio n. 17
0
        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;
        }
Esempio n. 18
0
        internal RollbarEventArgs(
            RollbarLogger logger,
            Payload payload
            )
        {
            Assumption.AssertNotNull(logger, nameof(logger));

            this._logger = logger;
            if (payload != null)
            {
                this.Payload = JsonConvert.SerializeObject(payload);
            }
        }
Esempio n. 19
0
        private RollbarResponse Process(Payload payload, RollbarLogger logger)
        {
            var client = new RollbarClient(logger.Config);

            IEnumerable <string> safeScrubFields = logger.Config.GetSafeScrubFields();

            RollbarResponse response = null;
            int             retries  = 3;

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

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

            return(response);
        }
Esempio n. 20
0
 /// <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="custom">The custom.</param>
 /// <param name="timeoutAt">The timeout at.</param>
 /// <param name="signal">The signal.</param>
 public PayloadBundle(
     RollbarLogger rollbarLogger,
     IRollbarPackage payloadPackage,
     ErrorLevel level,
     IDictionary <string, object> custom,
     DateTime?timeoutAt,
     SemaphoreSlim signal
     )
     : this(rollbarLogger, payloadPackage as object, level, custom, timeoutAt, signal)
 {
     if (payloadPackage != null)
     {
         IRollbarPackage package = ApplyCustomKeyValueDecorator(payloadPackage);
         this._rollbarPackage = package;
     }
 }
Esempio n. 21
0
 internal RollbarEventArgs(
     RollbarLogger logger,
     object dataObject
     )
 {
     this._logger = logger;
     if (dataObject != null)
     {
         try
         {
             this.Payload = JsonConvert.SerializeObject(dataObject);
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex, $"{nameof(RollbarEventArgs)}.{nameof(this.Payload)}");
         }
     }
 }
Esempio n. 22
0
        /// <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>
        /// <param name="timeoutAt">The timeout at.</param>
        /// <param name="signal">The signal.</param>
        public PayloadBundle(
            RollbarLogger rollbarLogger,
            object payloadObject,
            ErrorLevel level,
            IDictionary <string, object> custom,
            DateTime?timeoutAt,
            SemaphoreSlim signal
            )
        {
            Assumption.AssertNotNull(rollbarLogger, nameof(rollbarLogger));
            Assumption.AssertNotNull(payloadObject, nameof(payloadObject));

            this._rollbarLogger = rollbarLogger;
            this._payloadObject = payloadObject;
            this._level         = level;
            this._custom        = custom;
            this._timeoutAt     = timeoutAt;
            this._signal        = signal;
        }
        /// <summary>
        /// Reports the specified rollbar logger.
        /// </summary>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        /// <param name="dataObject">The data object.</param>
        /// <param name="rollbarError">The rollbar error.</param>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public static void Report(
            RollbarLogger rollbarLogger,
            object dataObject,
            InternalRollbarError rollbarError,
            string message,
            Exception exception
            )
        {
            var rollbarException = new RollbarException(rollbarError, message ?? rollbarError.ToString(), exception);
            var rollbarEvent     = new InternalErrorEventArgs(rollbarLogger, dataObject, rollbarException, rollbarException.Message);

            if (rollbarLogger != null)
            {
                rollbarLogger.OnRollbarEvent(rollbarEvent);
            }
            else
            {
                RollbarQueueController.Instance.OnRollbarEvent(rollbarEvent);
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarClient"/> class.
        /// </summary>
        /// <param name="rollbarLogger">The rollbar logger.</param>
        public RollbarClient(RollbarLogger rollbarLogger)
        {
            Assumption.AssertNotNull(rollbarLogger, nameof(rollbarLogger));
            Assumption.AssertNotNull(rollbarLogger.Config, nameof(rollbarLogger.Config));

            this._rollbarLogger = rollbarLogger;

            this._payloadPostUri =
                new Uri($"{this._rollbarLogger.Config.EndPoint}item/");
            this._httpClient =
                RollbarQueueController.Instance.ProvideHttpClient(
                    this._rollbarLogger.Config.ProxyAddress,
                    this._rollbarLogger.Config.ProxyUsername,
                    this._rollbarLogger.Config.ProxyPassword
                    );

            var header = new MediaTypeWithQualityHeaderValue("application/json");

            if (!this._httpClient.DefaultRequestHeaders.Accept.Contains(header))
            {
                this._httpClient.DefaultRequestHeaders.Accept.Add(header);
            }

            var sp = ServicePointManager.FindServicePoint(new Uri(this._rollbarLogger.Config.EndPoint));

            try
            {
                sp.ConnectionLeaseTimeout = 60 * 1000; // 1 minute
            }
#pragma warning disable CS0168                         // Variable is declared but never used
            catch (NotImplementedException ex)
#pragma warning restore CS0168                         // Variable is declared but never used
            {
                // just a crash prevention.
                // this is a work around the unimplemented property within Mono runtime...
            }

            this._payloadTruncationStrategy = new IterativeTruncationStrategy();
        }
Esempio n. 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadDropEventArgs"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="dropReason">The drop reason.</param>
 internal PayloadDropEventArgs(RollbarLogger logger, Payload payload, DropReason dropReason)
     : base(logger, payload)
 {
     this.Reason = dropReason;
 }
 internal RollbarApiErrorEventArgs(RollbarLogger logger, Payload payload, RollbarResponse response)
     : base(logger, payload, response)
 {
     Assumption.AssertNotNull(response, nameof(response));
     Assumption.AssertGreaterThan(response.Error, 0, nameof(response.Error));
 }
Esempio n. 27
0
 internal CommunicationEventArgs(RollbarLogger logger, Payload payload, RollbarResponse response)
     : base(logger, payload)
 {
     this.Response = response;
 }
Esempio n. 28
0
 internal RollbarConfig(RollbarLogger logger)
 {
     this._logger = logger;
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransmissionOmittedEventArgs"/> class.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="payload">The payload.</param>
 internal TransmissionOmittedEventArgs(RollbarLogger logger, Payload payload)
     : base(logger, payload)
 {
 }
Esempio n. 30
0
        internal RollbarConfig(RollbarLogger logger)
        {
            this._logger = logger;

            this.SetDefaults();
        }