static void Main(string[] args)
        {
            // Define RollbarInfrastructureConfig:
            RollbarInfrastructureConfig rollbarInfrastructureConfig =
                new RollbarInfrastructureConfig(
                    RollbarSamplesSettings.AccessToken,
                    RollbarSamplesSettings.Environment
                    );

            // Add RollbarSink to the Serilog Logger using pre-configured RollbarConfig:
            Serilog.Core.Logger log = new LoggerConfiguration()
                                      .MinimumLevel.Information()
                                      .WriteTo.Console()
                                      .WriteTo.RollbarSink(rollbarInfrastructureConfig, TimeSpan.FromSeconds(3))
                                      .CreateLogger();

            var position  = new { Latitude = 25, Longitude = 134 };
            var elapsedMs = 34;

            // an informational trace via Serilog:
            log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);

            // let's simulate some exception logging via Serilog:
            try
            {
                throw new ApplicationException("Oy vey via Serilog!");
            }
            catch (Exception ex)
            {
                log.Error(ex, "What happened?");
            }
        }
        public static void ConfigureRollbar()
        {
            RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );

            RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();

            dataSecurityOptions.ScrubFields = new string[]
            {
                "access_token", // normally, you do not want scrub this specific field (it is operationally critical), but it just proves safety net built into the notifier...
                "username",
            };
            rollbarInfrastructureConfig.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            RollbarPayloadAdditionOptions payloadAdditionOptions = new RollbarPayloadAdditionOptions();

            payloadAdditionOptions.Person = new Person("007")
            {
                Email    = "*****@*****.**",
                UserName = "******"
            };
            rollbarInfrastructureConfig.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Reconfigure(payloadAdditionOptions);

            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            // optionally, if you would like to monitor this Rollbar instance's internal events within your application:
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;
        }
Example #3
0
        private static void LoadDataSecurityOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
        {
            RollbarDataSecurityOptions dataSecurityOptions = new();

            if (rollbarConfigSection.ScrubFields != null && rollbarConfigSection.ScrubFields.Length > 0)
            {
                dataSecurityOptions.ScrubFields =
                    string.IsNullOrEmpty(rollbarConfigSection.ScrubFields) ? Array.Empty <string>()
                    : rollbarConfigSection.ScrubFields.Split(listValueSplitters, StringSplitOptions.RemoveEmptyEntries);
            }

            if (rollbarConfigSection.ScrubSafelistFields != null && rollbarConfigSection.ScrubSafelistFields.Length > 0)
            {
                dataSecurityOptions.ScrubSafelistFields =
                    string.IsNullOrEmpty(rollbarConfigSection.ScrubSafelistFields) ? Array.Empty <string>()
                    : rollbarConfigSection.ScrubSafelistFields.Split(listValueSplitters, StringSplitOptions.RemoveEmptyEntries);
            }

            if (rollbarConfigSection.PersonDataCollectionPolicies.HasValue)
            {
                dataSecurityOptions.PersonDataCollectionPolicies = rollbarConfigSection.PersonDataCollectionPolicies.Value;
            }

            if (rollbarConfigSection.IpAddressCollectionPolicy.HasValue)
            {
                dataSecurityOptions.IpAddressCollectionPolicy = rollbarConfigSection.IpAddressCollectionPolicy.Value;
            }

            config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);
        }
        /// <summary>
        /// Configures the Rollbar singleton-like notifier.
        /// </summary>
        private void ConfigureRollbarInfrastructure()
        {
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );

            config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = ErrorLevel.Debug;

            //RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();
            //dataSecurityOptions.ScrubFields = new string[]
            //{
            //    "url",
            //    "method",
            //};
            //config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            var telemetryOptions = new RollbarTelemetryOptions(true, 20)
            {
                TelemetryAutoCollectionTypes = TelemetryType.Log | TelemetryType.Error | TelemetryType.Network
            };

            config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);

            RollbarInfrastructure.Instance.Init(config);
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;

            var telemetryBody = new LogTelemetry("Rollbar infrastructure initialized!");

            RollbarInfrastructure.Instance.TelemetryCollector.Capture(new Telemetry(TelemetrySource.Server, TelemetryLevel.Info, telemetryBody));

            RollbarLocator.RollbarInstance.Info("Rollbar is ready to roll!");
        }
        /// <summary>
        /// Configures the Rollbar infrastructure.
        /// </summary>
        private static void ConfigureRollbarInfrastructure()
        {
            // minimally required Rollbar configuration:
            RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );
            // optionally, add data scrubbing options:
            RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();

            dataSecurityOptions.ScrubFields = new string[]
            {
                "access_token", // normally, you do not want scrub this specific field (it is operationally critical), but it just proves safety net built into the notifier...
                "username",
            };
            rollbarInfrastructureConfig.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            // initialize Rollbar infrastructure:
            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            // optionally, if you would like to monitor all Rollbar instances' internal events within your application:
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;

            // optionally, if you would like to monitor this Rollbar instance's internal events within your application:
            RollbarLocator.RollbarInstance.InternalEvent += OnRollbarInternalEvent;

            // basic test:
            RollbarLocator.RollbarInstance.Info($"{typeof(MvcApplication).Namespace}: Rollbar is up and running!");
        }
Example #6
0
        /// <summary>
        /// Configures Rollbar-specific services.
        /// </summary>
        /// <param name="services">The service collection.</param>
        /// <param name="rollbarLogLevel">The LogLevel starting from which to log with Rollbar.</param>
        /// <param name="rollbarInfrastructureConfig">The valid Rollbar Infrastructure Configuration.</param>
        /// <param name="rollbarInternalEventHandler">Optional Rollbar Internal Event Handler.</param>
        /// <returns>N/A</returns>
        public static void ConfigureServices(
            IServiceCollection services,
            LogLevel rollbarLogLevel,
            RollbarInfrastructureConfig rollbarInfrastructureConfig,
            EventHandler <RollbarEventArgs>?rollbarInternalEventHandler = null
            )
        {
            if (!services.Any(s => s.ServiceType == typeof(IHttpContextAccessor)))
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            }

            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            if (rollbarInternalEventHandler != null &&
                RollbarInfrastructure.Instance.QueueController != null
                )
            {
                RollbarInfrastructure.Instance.QueueController.InternalEvent += rollbarInternalEventHandler;
            }

            services.AddRollbarLogger(loggerOptions =>
            {
                loggerOptions.Filter = (loggerName, logLevel) => logLevel >= rollbarLogLevel;
            });
        }
 static PayloadQueueFixture()
 {
     infrastructureConfig = new RollbarInfrastructureConfig(RollbarUnitTestSettings.AccessToken, RollbarUnitTestSettings.Environment);
     if (!RollbarInfrastructure.Instance.IsInitialized)
     {
         RollbarInfrastructure.Instance.Init(infrastructureConfig);
     }
 }
        /// <summary>
        /// Loads the application settings.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="appSettings">The application settings.</param>
        /// <returns>false when the configuration was not found, otherwise true.</returns>
        public static bool LoadAppSettings(RollbarInfrastructureConfig config, IConfiguration appSettings)
        {
            Assumption.AssertNotNull(config, nameof(config));

            const string rollbarAppConfigSectionName = "Rollbar";

            return(AppSettingsUtility.LoadAppSettings(config, rollbarAppConfigSectionName, appSettings));
        }
Example #9
0
        private static void LoadTelemetryOptions(RollbarInfrastructureConfig config)
        {
            RollbarTelemetryOptions telemetryOptions = new();

            if (AppConfigUtility.LoadAppSettings(telemetryOptions))
            {
                config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);
            }
        }
Example #10
0
        /// <summary>
        /// Configures the Rollbar singleton-like notifier.
        /// </summary>
        private static void ConfigureRollbarSingleton()
        {
            // minimally required Rollbar configuration:
            RollbarInfrastructureConfig config =
                new RollbarInfrastructureConfig(
                    RollbarSamplesSettings.AccessToken,
                    RollbarSamplesSettings.Environment
                    );

            // optional:
            RollbarOfflineStoreOptions offlineStoreOptions = new RollbarOfflineStoreOptions();

            offlineStoreOptions.EnableLocalPayloadStore = true;
            config.RollbarOfflineStoreOptions.Reconfigure(offlineStoreOptions);

            // optional:
            RollbarTelemetryOptions telemetryOptions = new RollbarTelemetryOptions(true, 3);

            config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);

            // optional:
            //HttpProxyOptions proxyOptions = new HttpProxyOptions("http://something.com");
            //config.RollbarLoggerConfig.HttpProxyOptions.Reconfigure(proxyOptions);

            // optional:
            RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();

            dataSecurityOptions.ScrubFields = new string[]
            {
                "access_token", // normally, you do not want scrub this specific field (it is operationally critical), but it just proves safety net built into the notifier...
                "username",
                "criticalObj[Sample.NetCore.ConsoleApp.Program+InstanceType]._baseNullField",
                "data.custom.criticalObj[Sample.NetCore.ConsoleApp.Program+InstanceType].<TypeName>k__BackingField",
            };
            config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            // optional:
            RollbarPayloadAdditionOptions payloadAdditionOptions = new RollbarPayloadAdditionOptions();

            payloadAdditionOptions.Person = new Person()
            {
                Id       = "007",
                Email    = "*****@*****.**",
                UserName = "******",
            };
            config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Reconfigure(payloadAdditionOptions);

            // initialize the Rollbar Infrastructure:
            RollbarInfrastructure.Instance.Init(config);

            // optional step if you would like to monitor all Rollbar instances' internal events within your application:
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;

            // optional step if you would like to monitor this Rollbar instance's internal events within your application:
            //RollbarLocator.RollbarInstance.InternalEvent += OnRollbarInternalEvent;
        }
Example #11
0
        /// <summary>
        /// Loads the rollbar configuration.
        /// </summary>
        /// <returns>IRollbarConfig or null if no configuration store was found.</returns>
        public IRollbarInfrastructureConfig?LoadRollbarConfig()
        {
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig("seedToken");

            if (this.Load(config))
            {
                return(config);
            }
            return(null);
        }
Example #12
0
        static void Main(string[] args)
        {
            RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig();

            AppSettingsUtility.LoadAppSettings(rollbarInfrastructureConfig);
            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            RollbarLocator.RollbarInstance.AsBlockingLogger(TimeSpan.FromSeconds(3))
            .Info($"{typeof(Program).Namespace} sample: Rollbar Notifier is alive based on appsetting.json!");
        }
        public void SetupFixture()
        {
            RollbarInfrastructureConfig infrastructureConfig = new RollbarInfrastructureConfig(RollbarUnitTestSettings.AccessToken, RollbarUnitTestSettings.Environment);

            RollbarInfrastructure.Instance.Init(infrastructureConfig);
            this._rollbarCommEvents.Clear();
            this._rollbarCommErrorEvents.Clear();
            RollbarQueueController.Instance.FlushQueues();
            RollbarQueueController.Instance.InternalEvent += Instance_InternalEvent;
        }
        /// <summary>
        /// Configures the Rollbar singleton-like notifier.
        /// </summary>
        private void ConfigureRollbar()
        {
            RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );

            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            // optionally, if you would like to monitor Rollbar internal events within your application:
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;
        }
        /// <summary>
        /// Loads the application settings.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="appSettingsFolderPath">The application settings folder path.</param>
        /// <param name="appSettingsFileName">Name of the application settings file.</param>
        /// <returns>false when the configuration was not found, otherwise true.</returns>
        public static bool LoadAppSettings(RollbarInfrastructureConfig config, string appSettingsFolderPath, string appSettingsFileName)
        {
            Assumption.AssertNotNull(config, nameof(config));

            IConfiguration?appSettingsConfig = AppSettingsUtility.LoadAppSettings(appSettingsFolderPath, appSettingsFileName);

            if (appSettingsConfig == null)
            {
                return(false);
            }

            AppSettingsUtility.LoadAppSettings(config, appSettingsConfig);
            return(true);
        }
        public void TestBasics()
        {
            var config = new RollbarInfrastructureConfig();

            Console.WriteLine(config.TraceAsString());

            var results = config.Validate();

            Assert.AreEqual(1, results.Count, "One Validation Rule failed!");
            Console.WriteLine("Validation Results:");
            foreach (var result in results)
            {
                Console.WriteLine($"  {result}");
            }
            Console.WriteLine();
        }
Example #17
0
        /// <summary>
        /// Provides configuration for RollbarSink.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="rollbarAccessToken">The Rollbar access token.</param>
        /// <param name="rollbarEnvironment">The Rollbar environment.</param>
        /// <param name="rollbarBlockingLoggingTimeout">The Rollbar blocking logging timeout.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <param name="restrictedToMinimumLevel">
        ///   The minimum level for events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.
        /// </param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
        /// <returns>LoggerConfiguration.</returns>
        public static LoggerConfiguration RollbarSink(
            this LoggerSinkConfiguration loggerConfiguration,
            string rollbarAccessToken,
            string rollbarEnvironment,
            TimeSpan?rollbarBlockingLoggingTimeout,
            IFormatProvider?formatProvider,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch?levelSwitch         = null
            )
        {
            RollbarDestinationOptions    destinationOptions = new RollbarDestinationOptions(rollbarAccessToken, rollbarEnvironment);
            IRollbarInfrastructureConfig config             = new RollbarInfrastructureConfig();

            config.RollbarLoggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);

            return(loggerConfiguration.RollbarSink(config, rollbarBlockingLoggingTimeout, formatProvider, restrictedToMinimumLevel, levelSwitch));
        }
Example #18
0
        private static void LoadDestinationOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
        {
            if (!string.IsNullOrWhiteSpace(rollbarConfigSection.AccessToken))
            {
                RollbarDestinationOptions destinationOptions = new(rollbarConfigSection.AccessToken);

                if (!string.IsNullOrWhiteSpace(rollbarConfigSection.Environment))
                {
                    destinationOptions.Environment = rollbarConfigSection.Environment;
                }

                if (!string.IsNullOrWhiteSpace(rollbarConfigSection.EndPoint))
                {
                    destinationOptions.EndPoint = rollbarConfigSection.EndPoint;
                }

                config.RollbarLoggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);
            }
        }
Example #19
0
        /// <summary>
        /// Configures the Rollbar singleton-like notifier.
        /// </summary>
        private void ConfigureRollbarSingleton()
        {
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );

            config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = ErrorLevel.Debug;
            //RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();
            //dataSecurityOptions.ScrubFields = new string[]
            //{
            //    "url",
            //    "method",
            //};
            //config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            RollbarInfrastructure.Instance.Init(config);
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;
        }
Example #20
0
        private static void LoadHttpProxyOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
        {
            if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyAddress))
            {
                HttpProxyOptions httpProxyOptions = new(rollbarConfigSection.ProxyAddress);

                if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyUsername))
                {
                    httpProxyOptions.ProxyUsername = rollbarConfigSection.ProxyUsername;
                }

                if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyPassword))
                {
                    httpProxyOptions.ProxyPassword = rollbarConfigSection.ProxyPassword;
                }

                config.RollbarLoggerConfig.HttpProxyOptions.Reconfigure(httpProxyOptions);
            }
        }
Example #21
0
        /// <summary>
        /// Configures the Rollbar.
        /// </summary>
        private void ConfigureRollbar(IServiceCollection services)
        {
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );

            config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = ErrorLevel.Debug;
            config.RollbarInfrastructureOptions.MaxItems = 500;
            //RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();
            //dataSecurityOptions.ScrubFields = new string[]
            //{
            //    "url",
            //    "method",
            //};
            //config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            RollbarMiddleware.ConfigureServices(services, LogLevel.Information, config, OnRollbarInternalEvent);
        }
        // STEP.2 - Setup Rollbar Infrastructure:
        private void ConfigureRollbarInfrastructure()
        {
            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig(
                RollbarSamplesSettings.AccessToken,
                RollbarSamplesSettings.Environment
                );
            RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();

            dataSecurityOptions.ScrubFields = new string[]
            {
                "url",
                "method",
            };
            config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);

            RollbarInfrastructure.Instance.Init(config);

            // Optionally:
            RollbarInfrastructure.Instance.QueueController.InternalEvent += OnRollbarInternalEvent;
        }
Example #23
0
        static void Main(string[] args)
        {
            const string rollbarAccessToken = RollbarSamplesSettings.AccessToken;
            const string rollbarEnvironment = RollbarSamplesSettings.Environment;

            var config = new RollbarInfrastructureConfig(rollbarAccessToken, rollbarEnvironment); // minimally required Rollbar configuration

            RollbarInfrastructure.Instance.Init(config);

            Console.WriteLine("Hello World!");

            RollbarLocator.RollbarInstance.AsBlockingLogger(TimeSpan.FromSeconds(5))
            .Info("Sample.RollbarWithinStronglyNamedAssembly sample: Basic info log example.")
            .Debug("Sample.RollbarWithinStronglyNamedAssembly sample: First debug log.")
            .Error(new NullReferenceException("Sample.RollbarWithinStronglyNamedAssembly sample: null reference exception."))
            .Error(new Exception("Sample.RollbarWithinStronglyNamedAssembly sample: trying out the TraceChain", new NullReferenceException()))
            ;

            Console.WriteLine("Hello Rollbar!");
        }
Example #24
0
        private static void LoadOfflinePayloadStoreOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
        {
            RollbarOfflineStoreOptions offlineStoreOptions = new();

            if (rollbarConfigSection.EnableLocalPayloadStore.HasValue)
            {
                offlineStoreOptions.EnableLocalPayloadStore = rollbarConfigSection.EnableLocalPayloadStore.Value;
            }

            if (!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreFileName))
            {
                offlineStoreOptions.LocalPayloadStoreFileName = rollbarConfigSection.LocalPayloadStoreFileName;
            }

            if (!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreLocationPath))
            {
                offlineStoreOptions.LocalPayloadStoreLocationPath = rollbarConfigSection.LocalPayloadStoreLocationPath;
            }

            config.RollbarOfflineStoreOptions.Reconfigure(offlineStoreOptions);
        }
        public static RollbarInfrastructureConfig GetLiveTestRollbarInfrastructureConfig()
        {
            var config =
                new RollbarInfrastructureConfig();

            var destinationOptions =
                RollbarUnitTestEnvironmentUtil.GetLiveTestRollbarDestinationOptions();

            config
            .RollbarLoggerConfig
            .RollbarDestinationOptions
            .Reconfigure(destinationOptions);

            var infrastructureOptions = new RollbarInfrastructureOptions();

            infrastructureOptions.PayloadPostTimeout = TimeSpan.FromSeconds(3);
            config
            .RollbarInfrastructureOptions
            .Reconfigure(infrastructureOptions);

            return(config);
        }
Example #26
0
        /// <summary>
        /// Loads the application settings.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="rollbarConfigSection">The application settings.</param>
        /// <returns>false when the configuration was not found, otherwise true.</returns>
        public static bool LoadAppSettings(RollbarInfrastructureConfig config, RollbarConfigSection?rollbarConfigSection)
        {
            if (rollbarConfigSection == null)
            {
                return(false);
            }

            LoadInfrastructureOptions(config, rollbarConfigSection);
            LoadOfflinePayloadStoreOptions(config, rollbarConfigSection);
            LoadDestinationOptions(config, rollbarConfigSection);
            LoadDeveloperOptions(config, rollbarConfigSection);
            LoadHttpProxyOptions(config, rollbarConfigSection);
            LoadDataSecurityOptions(config, rollbarConfigSection);
            LoadTelemetryOptions(config);

            var  validationResults   = config.Validate();
            bool configLoadingResult =
                (validationResults == null) || (validationResults.Count == 0);

            Debug.Assert(configLoadingResult);
            return(configLoadingResult);
        }
Example #27
0
        private static void LoadDeveloperOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
        {
            if (rollbarConfigSection.Enabled.HasValue)
            {
                config.RollbarLoggerConfig.RollbarDeveloperOptions.Enabled = rollbarConfigSection.Enabled.Value;
            }

            if (rollbarConfigSection.Transmit.HasValue)
            {
                config.RollbarLoggerConfig.RollbarDeveloperOptions.Transmit = rollbarConfigSection.Transmit.Value;
            }

            if (rollbarConfigSection.RethrowExceptionsAfterReporting.HasValue)
            {
                config.RollbarLoggerConfig.RollbarDeveloperOptions.RethrowExceptionsAfterReporting = rollbarConfigSection.RethrowExceptionsAfterReporting.Value;
            }

            if (rollbarConfigSection.LogLevel.HasValue)
            {
                config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = rollbarConfigSection.LogLevel.Value;
            }
        }
Example #28
0
        /// <summary>
        /// Gets the Rollbar trace listener configuration.
        /// </summary>
        /// <returns>RollbarConfig.</returns>
        private IRollbarLoggerConfig?GetRollbarTraceListenerConfig()
        {
            if (string.IsNullOrWhiteSpace(this.Attributes[RollbarTraceListenerAttributes.rollbarAccessToken.ToString()]))
            {
                return(null);
            }

            if (!RollbarInfrastructure.Instance.IsInitialized)
            {
#if !NETFX_47nOlder
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
                {
                    // We are running within Blazor WASM runtime environment that is known to be single threaded in its nature
                    // at least at the moment, so no background threads are allowed and our infrastructure depends on the threads.
                    // Hence, we can not initialize the infrastructure:
                    // NO-OP...
                    return(null);
                }
#endif

                // It is safe to assume we can use the infrastructure:
                RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig(
                    this.Attributes[RollbarTraceListenerAttributes.rollbarAccessToken.ToString()],
                    this.Attributes[RollbarTraceListenerAttributes.rollbarEnvironment.ToString()]
                    );
                RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);
                return(rollbarInfrastructureConfig.RollbarLoggerConfig);
            }
            else
            {
                RollbarLoggerConfig rollbarLoggerConfig = new RollbarLoggerConfig(
                    this.Attributes[RollbarTraceListenerAttributes.rollbarAccessToken.ToString()],
                    this.Attributes[RollbarTraceListenerAttributes.rollbarEnvironment.ToString()]
                    );
                return(rollbarLoggerConfig);
            }
        }
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureLogging((logging) => {
            // seed Rollbar infrastructure configuration:
            RollbarInfrastructureConfig rollbarInfrastructureConfig = new RollbarInfrastructureConfig();

            // reconfigure the seed from the appsettings.json file:
            if (!AppSettingsUtility.LoadAppSettings(rollbarInfrastructureConfig))
            {
                throw new ApplicationException("Couldn't load Rollbar configuration!");
            }

            // init the Rollbar infrastructure with the loaded configuration:
            RollbarInfrastructure.Instance.Init(rollbarInfrastructureConfig);

            // add a well-configured RollbarLoggerProvider:
            logging.ClearProviders();
            logging.AddProvider(new RollbarLoggerProvider(rollbarInfrastructureConfig.RollbarLoggerConfig));
        }
                          )
        .ConfigureServices((hostContext, services) =>
        {
            services.AddHostedService <Worker>();
        });
Example #30
0
        public void CustomTelemetryOptionsMakeIntoTelemetryCollector()
        {
            int expectedTelemetryQueueDepth = 20;

            var config = new RollbarInfrastructureConfig("access_token", "special_environment");

            Assert.IsFalse(config.RollbarTelemetryOptions.TelemetryEnabled);
            Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryQueueDepth != expectedTelemetryQueueDepth);
            Assert.IsTrue(config.RollbarTelemetryOptions.TelemetryAutoCollectionTypes == TelemetryType.None);

            var telemetryOptions = new RollbarTelemetryOptions(true, 20)
            {
                TelemetryAutoCollectionTypes = TelemetryType.Log | TelemetryType.Error | TelemetryType.Network
            };

            config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);


            if (RollbarInfrastructure.Instance.IsInitialized)
            {
                RollbarInfrastructure.Instance.Config.Reconfigure(config);
            }
            else
            {
                RollbarInfrastructure.Instance.Init(config);
            }

            Assert.IsTrue(RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryEnabled);
            Assert.AreEqual(expectedTelemetryQueueDepth, RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryQueueDepth);
            Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Log) == TelemetryType.Log);
            Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Error) == TelemetryType.Error);
            Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Network) == TelemetryType.Network);
            Assert.IsTrue((RollbarInfrastructure.Instance.TelemetryCollector.Config.TelemetryAutoCollectionTypes & TelemetryType.Manual) == TelemetryType.None);

            Assert.AreEqual(expectedTelemetryQueueDepth, RollbarInfrastructure.Instance.TelemetryCollector.QueueDepth);
        }