Exemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        /// <summary>
        /// Enqueues the data.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="level">The level.</param>
        /// <param name="custom">The custom.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="signal">The signal.</param>
        /// <returns>PayloadBundle.</returns>
        internal PayloadBundle EnqueueData(
            object dataObject,
            ErrorLevel level,
            IDictionary <string, object> custom,
            TimeSpan?timeout     = null,
            SemaphoreSlim signal = null
            )
        {
            // here is the last chance to decide if we need to actually send this payload
            // based on the current config settings and rate-limit conditions:
            if (string.IsNullOrWhiteSpace(this._config.AccessToken) ||
                this._config.Enabled == false ||
                (this._config.LogLevel.HasValue && level < this._config.LogLevel.Value) ||
                ((this._payloadQueue.AccessTokenQueuesMetadata != null) && this._payloadQueue.AccessTokenQueuesMetadata.IsTransmissionSuspended)
                )
            {
                // nice shortcut:
                return(null);
            }

            if (this._config.RethrowExceptionsAfterReporting)
            {
                System.Exception exception = dataObject as System.Exception;
                if (exception == null)
                {
                    if (dataObject is Data data && data.Body != null)
                    {
                        exception = data.Body.OriginalException;
                    }
                }

                if (exception != null)
                {
                    try
                    {
                        // Here we need to create another logger instance with similar config but configured not to re-throw.
                        // This would prevent infinite recursive calls (in case if we used this instance or any re-throwing instance).
                        // Because we will be re-throwing the exception after reporting, let's report it fully-synchronously.
                        // This logic is on a heavy side. But, fortunately, RethrowExceptionsAfterReporting is intended to be
                        // a development time option:
                        var config = new RollbarConfig();
                        config.Reconfigure(this._config);
                        config.RethrowExceptionsAfterReporting = false;
                        using (var rollbar = RollbarFactory.CreateNew(config))
                        {
                            rollbar.AsBlockingLogger(TimeSpan.FromSeconds(1)).Log(level, dataObject, custom);
                        }
                    }
                    catch
                    {
                        // In case there was a TimeoutException (or any un-expected exception),
                        // there is nothing we can do here.
                        // We tried our best...
                    }
                    finally
                    {
                        if (exception is AggregateException aggregateException)
                        {
                            exception = aggregateException.Flatten();
                            ExceptionDispatchInfo.Capture(
                                exception.InnerException).Throw();
                        }
                        else
                        {
                            ExceptionDispatchInfo.Capture(exception).Throw();
                        }
                    }

                    return(null);
                }
            }


            PayloadBundle payloadBundle = null;

            try
            {
                payloadBundle = CreatePayloadBundle(dataObject, level, custom, timeout, signal);
            }
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.BundlingError,
                    null,
                    exception,
                    payloadBundle
                    );
                return(null);
            }

            try
            {
                this._payloadQueue.Enqueue(payloadBundle);
            }
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.EnqueuingError,
                    null,
                    exception,
                    payloadBundle
                    );
            }

            return(payloadBundle);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates the new instance of IRollbar.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <returns></returns>
 public static IRollbar CreateNew(IRollbarConfig rollbarConfig)
 {
     return(RollbarFactory.CreateNew(false, rollbarConfig));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates the new instance of IRollbar.
 /// </summary>
 /// <returns></returns>
 public static IRollbar CreateNew()
 {
     return(RollbarFactory.CreateNew(null));
 }
        /// <summary>
        /// Enqueues the data.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="level">The level.</param>
        /// <param name="custom">The custom.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="signal">The signal.</param>
        /// <returns>PayloadBundle.</returns>
        internal PayloadBundle?EnqueueData(
            object dataObject,
            ErrorLevel level,
            IDictionary <string, object?>?custom,
            TimeSpan?timeout     = null,
            SemaphoreSlim?signal = null
            )
        {
            // here is the last chance to decide if we need to actually send this payload
            // based on the current config settings and rate-limit conditions:
            if (string.IsNullOrWhiteSpace(this._config.RollbarDestinationOptions.AccessToken) ||
                !this._config.RollbarDeveloperOptions.Enabled ||
                (level < this._config.RollbarDeveloperOptions.LogLevel)
                )
            {
                // nice shortcut:
                return(null);
            }

            if (this._config.RollbarDeveloperOptions.RethrowExceptionsAfterReporting)
            {
                System.Exception?exception = dataObject as System.Exception;
                if (exception == null &&
                    dataObject is Data data &&
                    data.Body != null
                    )
                {
                    exception = data.Body.OriginalException;
                }

                if (exception != null)
                {
                    try
                    {
                        // Here we need to create another logger instance with similar config but configured not to re-throw.
                        // This would prevent infinite recursive calls (in case if we used this instance or any re-throwing instance).
                        // Because we will be re-throwing the exception after reporting, let's report it fully-synchronously.
                        // This logic is on a heavy side. But, fortunately, RethrowExceptionsAfterReporting is intended to be
                        // a development time option:
                        var config = new RollbarLoggerConfig();
                        config.Reconfigure(this._config);
                        config.RollbarDeveloperOptions.RethrowExceptionsAfterReporting = false;
                        using var rollbar = RollbarFactory.CreateNew(config);
                        rollbar.AsBlockingLogger(TimeSpan.FromSeconds(1)).Log(level, dataObject, custom);
                    }
#pragma warning disable CA1031 // Do not catch general exception types
                    catch
                    {
                        // In case there was a TimeoutException (or any un-expected exception),
                        // there is nothing we can do here.
                        // We tried our best...
                    }
#pragma warning restore CA1031 // Do not catch general exception types
                    finally
                    {
                        if (exception is AggregateException aggregateException)
                        {
                            exception = aggregateException.Flatten();
                        }
                        ExceptionDispatchInfo.Capture(exception).Throw();
                    }

                    return(null);
                }
            }


            PayloadBundle?payloadBundle = null;
            try
            {
                payloadBundle = CreatePayloadBundle(dataObject, level, custom, timeout, signal);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.BundlingError,
                    null,
                    exception,
                    payloadBundle
                    );
                return(null);
            }
#pragma warning restore CA1031 // Do not catch general exception types

            try
            {
                _ = this._rollbarClient.PostAsJsonAsync(payloadBundle);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (System.Exception exception)
            {
                RollbarErrorUtility.Report(
                    this,
                    dataObject,
                    InternalRollbarError.EnqueuingError,
                    null,
                    exception,
                    payloadBundle
                    );
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(payloadBundle);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates the new instance of IRollbar.
 /// </summary>
 /// <returns></returns>
 public static IRollbar CreateNew()
 {
     return(RollbarFactory.CreateNew(false));
 }