Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BodyPackage"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="bodyToPackage">The body to package.</param>
 /// <param name="custom">The custom.</param>
 public BodyPackage(IRollbarConfig rollbarConfig, Body bodyToPackage, IDictionary <string, object> custom)
     : base(false)
 {
     this._rollbarConfig = rollbarConfig;
     this._bodyToPackage = bodyToPackage;
     this._custom        = custom;
 }
Ejemplo n.º 2
0
        public RollbarClient(IRollbarConfig config, HttpClient httpClient)
        {
            Assumption.AssertNotNull(config, nameof(config));
            Assumption.AssertNotNull(httpClient, nameof(httpClient));

            this._config = config;

            this._payloadPostUri = new Uri($"{this._config.EndPoint}item/");


            this._httpClient = httpClient;

            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._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();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Data"/> class.
 /// </summary>
 /// <param name="config">The configuration.</param>
 /// <param name="body">The body.</param>
 public Data(
     IRollbarConfig config,
     Body body
     )
     : this(config, body, null, null)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarExceptionHandler" /> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="rollbarBlockingTimeout">The rollbar blocking timeout.</param>
 public RollbarExceptionHandler(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingTimeout
     )
     : base(rollbarErrorLevelByPlugInErrorLevel, customPrefix, rollbarConfig, rollbarBlockingTimeout)
 {
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Data" /> class.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="body">The body.</param>
        /// <param name="custom">The custom.</param>
        /// <param name="request">The request.</param>
        public Data(IRollbarConfig config, Body body, IDictionary <string, object> custom = null, Request request = null)
        {
            Assumption.AssertNotNull(config, nameof(config));
            Assumption.AssertNotNull(body, nameof(body));

            // snap config values:
            this.Environment = config.Environment;
            this.Level       = config.LogLevel;
            this.Person      = config.Person;
            this.Server      = config.Server;

            // set explicit values:
            this.Body    = body;
            this.Request = request;
            this.Custom  = custom;

            // set calculated values:
            this.Platform  = Data.DefaultPlatform;
            this.Framework = Data.DefaultFrameworkValue;
            this.Language  = Data.DefaultLanguage;
            this.Notifier  = new Dictionary <string, string>
            {
                { "name", "Rollbar.NET" },
                { "version", Data.NotifierAssemblyVersion },
            };
            this.GuidUuid  = Guid.NewGuid();
            this.Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarAppender"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The Rollbar configuration.</param>
 /// <param name="rollbarBlockingLoggingTimeout">The Rollbar blocking logging timeout.</param>
 public RollbarAppender(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingLoggingTimeout
     )
 {
     this._rollbarPlugIn = new RollbarPlugInCore(rollbarConfig, rollbarBlockingLoggingTimeout);
 }
Ejemplo n.º 8
0
        public static Data PackageAsPayloadData(
            IRollbarConfig rollbarConfig,
            ErrorLevel level,
            object obj,
            IDictionary <string, object> custom = null
            )
        {
            if (rollbarConfig.LogLevel.HasValue && level < rollbarConfig.LogLevel.Value)
            {
                // nice shortcut:
                return(null);
            }

            Data data = obj as Data;

            if (data != null)
            {
                data.Level = level;
                return(data);
            }

            Body body = obj as Body;

            if (body == null)
            {
                body = RollbarUtil.PackageAsPayloadBody(obj, ref custom);
            }

            data       = new Data(rollbarConfig, body, custom);
            data.Level = level;
            return(data);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Data" /> class.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="body">The body.</param>
        /// <param name="custom">The custom.</param>
        /// <param name="request">The request.</param>
        public Data(
            IRollbarConfig config,
            Body body,
            IDictionary <string, object> custom,
            Request request
            )
        {
            Assumption.AssertNotNull(body, nameof(body));

            // snap config values:
            if (config != null)
            {
                this.Environment = config.Environment;
                this.Level       = config.LogLevel;
                this.Person      = config.Person;
                this.Server      = config.Server;
            }

            // set explicit values:
            this.Body    = body;
            this.Request = request;
            this.Custom  = custom;

            // set calculated values:
            this.Platform  = Data.DefaultPlatform;
            this.Framework = Data.DefaultFrameworkValue;
            this.Language  = Data.DefaultLanguage;
            this.Notifier  = new Dictionary <string, string>
            {
                { "name", "Rollbar.NET" },
                { "version", Data.NotifierAssemblyVersion },
            };
            this.GuidUuid  = Guid.NewGuid();
            this.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(DateTime.UtcNow);
        }
Ejemplo n.º 10
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)
            {
                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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigAttributesPackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 public ConfigAttributesPackageDecorator(
     IRollbarPackage packageToDecorate,
     IRollbarConfig rollbarConfig
     )
     : this(packageToDecorate, rollbarConfig, false)
 {
 }
        public IRollbar Configure(IRollbarConfig settings)
        {
            Assumption.AssertNotNull(settings, nameof(settings));
            this._asyncLogger.Config.Reconfigure(settings);

            return(this);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarPlugInCore"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="rollbarBlockingTimeout">The rollbar blocking timeout.</param>
 public RollbarPlugInCore(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingTimeout
     )
     : base(rollbarErrorLevelByPlugInErrorLevel, customPrefix, rollbarConfig, rollbarBlockingTimeout)
 {
 }
Ejemplo n.º 14
0
        private void SnapProperties(HttpRequestMessage httpRequest, IRollbarConfig rollbarConfig)
        {
            Assumption.AssertNotNull(httpRequest, nameof(httpRequest));

            this.Url         = httpRequest.RequestUri?.AbsoluteUri;
            this.QueryString = httpRequest.RequestUri?.Query;
            this.Params      = null;

            this.Headers = new Dictionary <string, string>(httpRequest.Headers.Count());
            foreach (var header in httpRequest.Headers)
            {
                this.Headers.Add(header.Key, StringUtility.Combine(header.Value, ", "));
            }

            this.Method = httpRequest.Method.Method;
            switch (this.Method.ToUpperInvariant())
            {
            case "POST":
                var task = httpRequest.Content.ReadAsStringAsync();
                task.Wait();
                this.PostBody   = task.Result;
                this.PostParams = null;
                break;

            case "GET":
                this.GetParams = null;
                break;

            default:
                System.Diagnostics.Trace.WriteLine(
                    $"No-op processing {this.Method.ToUpperInvariant()} HTTP method."
                    );
                break;
            }

#if (NETFX)
            string       userIP = null;
            const string HttpContextProperty          = "MS_HttpContext";
            const string RemoteEndpointMessagePropery = "System.ServiceModel.Channels.RemoteEndpointMessageProperty";
            if (httpRequest.Properties.ContainsKey(HttpContextProperty))
            {
                HttpContextBase ctx = httpRequest.Properties[HttpContextProperty] as HttpContextBase;
                if (ctx != null)
                {
                    userIP = ctx.Request.UserHostAddress;
                }
            }
            else if (httpRequest.Properties.ContainsKey(RemoteEndpointMessagePropery))
            {
                RemoteEndpointMessageProperty remoteEndpoint =
                    httpRequest.Properties[RemoteEndpointMessagePropery] as RemoteEndpointMessageProperty;
                if (remoteEndpoint != null)
                {
                    userIP = remoteEndpoint.Address;
                }
            }
            this.UserIp =
                Request.DecideCollectableUserIPValue(userIP, rollbarConfig.IpAddressCollectionPolicy);
#endif
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Request"/> class.
 /// </summary>
 /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 public Request(
     IDictionary <string, object> arbitraryKeyValuePairs
     , IRollbarConfig rollbarConfig
     )
     : this(arbitraryKeyValuePairs, rollbarConfig, null)
 {
 }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="payloadPackage">The payload package.</param>
 /// <param name="level">The level.</param>
 public PayloadBundle(
     IRollbarConfig rollbarConfig,
     IRollbarPackage payloadPackage,
     ErrorLevel level
     )
     : this(rollbarConfig, payloadPackage, level, null, null, null)
 {
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Data"/> class.
 /// </summary>
 /// <param name="config">The configuration.</param>
 /// <param name="body">The body.</param>
 /// <param name="custom">The custom.</param>
 public Data(
     IRollbarConfig config,
     Body body,
     IDictionary <string, object> custom
     )
     : this(config, body, custom, null)
 {
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Data"/> class.
 /// </summary>
 /// <param name="config">The configuration.</param>
 /// <param name="body">The body.</param>
 /// <param name="request">The request.</param>
 public Data(
     IRollbarConfig config,
     Body body,
     Request request
     )
     : this(config, body, null, request)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PayloadBundle"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="payloadObject">The payload object.</param>
 /// <param name="level">The level.</param>
 public PayloadBundle(
     IRollbarConfig rollbarConfig,
     object payloadObject,
     ErrorLevel level
     )
     : this(rollbarConfig, payloadObject, level, null, null, null)
 {
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Rollbars the sink.
 /// </summary>
 /// <param name="loggerConfiguration">The logger configuration.</param>
 /// <param name="rollbarConfig">The Rollbar configuration.</param>
 /// <param name="rollbarBlockingLoggingTimeout">The Rollbar blocking logging timeout.</param>
 /// <param name="formatProvider">The format provider.</param>
 /// <returns>LoggerConfiguration.</returns>
 public static LoggerConfiguration RollbarSink(
     this LoggerSinkConfiguration loggerConfiguration,
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingLoggingTimeout,
     IFormatProvider formatProvider = null)
 {
     return(loggerConfiguration.Sink(new RollbarSink(rollbarConfig, rollbarBlockingLoggingTimeout, formatProvider)));
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbarTarget"/> class.
        /// </summary>
        /// <param name="rollbarConfig">The rollbar configuration.</param>
        public RollbarTarget(IRollbarConfig rollbarConfig)
        {
            OptimizeBufferReuse = true;
            Layout = "${message}";

            this._rollbarPlugIn =
                new RollbarPlugInCore(rollbarConfig, RollbarPlugInCore.DefaultRollbarBlockingTimeout, this);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarConfig rollbarConfig
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, false)
 {
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Configures the using specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns>IRollbar.</returns>
        public IRollbar Configure(IRollbarConfig settings)
        {
            ValidateConfiguration(settings);

            this._config.Reconfigure(settings);

            return(this);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarConfig rollbarConfig,
     bool mustApplySynchronously
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, mustApplySynchronously)
 {
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class.
 /// </summary>
 /// <param name="packageToDecorate">The package to decorate.</param>
 /// <param name="httpRequestMessage">The HTTP request message.</param>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
 public HttpRequestMessagePackageDecorator(
     IRollbarPackage packageToDecorate,
     HttpRequestMessage httpRequestMessage,
     IRollbarConfig rollbarConfig,
     IDictionary <string, object> arbitraryKeyValuePairs
     )
     : this(packageToDecorate, httpRequestMessage, rollbarConfig, arbitraryKeyValuePairs, false)
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarSink"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The Rollbar configuration.</param>
 /// <param name="rollbarBlockingLoggingTimeout">The Rollbar blocking logging timeout.</param>
 /// <param name="formatProvider">The format provider.</param>
 public RollbarSink(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingLoggingTimeout,
     IFormatProvider formatProvider
     )
 {
     this._rollbarPlugIn =
         new RollbarPlugInCore(rollbarConfig, rollbarBlockingLoggingTimeout, formatProvider);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarPlugInCore"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="rollbarBlockingTimeout">The rollbar blocking timeout.</param>
 /// <param name="rollbarTarget">The rollbar target.</param>
 public RollbarPlugInCore(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingTimeout,
     RollbarTarget rollbarTarget
     )
     : base(rollbarErrorLevelByPlugInErrorLevel, customPrefix, rollbarConfig, rollbarBlockingTimeout)
 {
     this._rollbarTarget = rollbarTarget;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbarPlugInCore"/> class.
 /// </summary>
 /// <param name="rollbarConfig">The rollbar configuration.</param>
 /// <param name="rollbarBlockingTimeout">The rollbar blocking timeout.</param>
 /// <param name="formatProvider">The format provider.</param>
 public RollbarPlugInCore(
     IRollbarConfig rollbarConfig,
     TimeSpan?rollbarBlockingTimeout,
     IFormatProvider formatProvider
     )
     : base(rollbarErrorLevelByPlugInErrorLevel, customPrefix, rollbarConfig, rollbarBlockingTimeout)
 {
     this._formatProvider = formatProvider;
 }
Ejemplo n.º 30
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
                      , NetPlatformExtensions.RollbarOptions rollbarOptions
                      , IHttpContextAccessor httpContextAccessor
                      )
     : base(name, rollbarConfig, rollbarOptions)
 {
     this._httpContextAccessor = httpContextAccessor;
 }