Пример #1
0
        public void LoadRollbarTelemetryAppSettingsTest()
        {
            TelemetryConfig config = new TelemetryConfig(false, 5, TelemetryType.None, TimeSpan.FromMilliseconds(100));

            Console.WriteLine(JsonConvert.SerializeObject(config));

            Assert.AreEqual(false, config.TelemetryEnabled);
            Assert.AreEqual(5, config.TelemetryQueueDepth);
            Assert.AreEqual(TelemetryType.None, config.TelemetryAutoCollectionTypes);
            Assert.AreEqual(TimeSpan.FromMilliseconds(100), config.TelemetryAutoCollectionInterval);

            AppSettingsUtility.LoadAppSettings(config, Path.Combine(Environment.CurrentDirectory, "TestData"), "appsettings.json");
            Console.WriteLine(JsonConvert.SerializeObject(config));

            // The test data looks like this:
            //===============================
            //"RollbarTelemetry": {
            //    "TelemetryEnabled": true,
            //    "TelemetryQueueDepth": 100,
            //    "TelemetryAutoCollectionTypes": "Network, Log, Error",
            //    "TelemetryAutoCollectionInterval":  "00:00:00.3000000",
            //},

            Assert.AreEqual(true, config.TelemetryEnabled);
            Assert.AreEqual(100, config.TelemetryQueueDepth);
            Assert.AreEqual(TelemetryType.Network | TelemetryType.Log | TelemetryType.Error, config.TelemetryAutoCollectionTypes);
            Assert.AreEqual(TimeSpan.FromMilliseconds(300), config.TelemetryAutoCollectionInterval);
        }
Пример #2
0
        /// <summary>
        /// Deduces the rollbar configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        public static IRollbarConfig DeduceRollbarConfig(IConfiguration configuration)
        {
            if (RollbarLocator.RollbarInstance.Config.AccessToken != null)
            {
                return(RollbarLocator.RollbarInstance.Config);
            }

            // Here we assume that the Rollbar singleton was not explicitly preconfigured
            // anywhere in the code (Program.cs or Startup.cs),
            // so we are trying to configure it from IConfiguration:

            Assumption.AssertNotNull(configuration, nameof(configuration));

            const string  defaultAccessToken = "none";
            RollbarConfig rollbarConfig      = new RollbarConfig(defaultAccessToken);

            AppSettingsUtility.LoadAppSettings(rollbarConfig, configuration);

            if (rollbarConfig.AccessToken == defaultAccessToken)
            {
                const string error = "Rollbar.NET notifier is not configured properly. A valid access token needs to be specified.";
                throw new Exception(error);
            }

            RollbarLocator.RollbarInstance
            .Configure(rollbarConfig);

            return(rollbarConfig);
        }
Пример #3
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!");
        }
Пример #4
0
        /// <summary>
        /// Deduces the rollbar telemetry configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        public static ITelemetryConfig DeduceRollbarTelemetryConfig(IConfiguration configuration)
        {
            TelemetryConfig config = new TelemetryConfig();

            AppSettingsUtility.LoadAppSettings(config, configuration);

            TelemetryCollector.Instance.Config.Reconfigure(config);

            return(config);
        }
Пример #5
0
        public void LoadRollbarAppSettingsTest()
        {
            RollbarConfig config = new RollbarConfig("default=none");

            AppSettingsUtility.LoadAppSettings(config, Path.Combine(Environment.CurrentDirectory, "TestData"), "appsettings.json");

            // The test data looks like this:
            //===============================
            //"Rollbar": {
            //    "AccessToken": "17965fa5041749b6bf7095a190001ded",
            //    "Environment": "unit-tests",
            //    "Enabled": true,
            //    "MaxReportsPerMinute": 160,
            //    "ReportingQueueDepth": 120,
            //    "LogLevel": "Info",
            //    "ScrubFields": [
            //      "ThePassword",
            //      "TheSecret"
            //    ],
            //    "Person": {
            //      "UserName": "******"
            //    },
            //    "PersonDataCollectionPolicies": "Username, Email",
            //    "IpAddressCollectionPolicy": "CollectAnonymized",
            //  }

            Assert.AreEqual("17965fa5041749b6bf7095a190001ded", config.AccessToken);
            Assert.AreEqual("unit-tests", config.Environment);
            Assert.AreEqual(true, config.Enabled);
            Assert.AreEqual(160, config.MaxReportsPerMinute);
            Assert.AreEqual(120, config.ReportingQueueDepth);
            Assert.AreEqual(ErrorLevel.Info, config.LogLevel.Value);
            Assert.IsTrue(config.ScrubFields.Length >= 2);
            Assert.AreEqual("jbond", config.Person.UserName);
            Assert.AreEqual(
                PersonDataCollectionPolicies.Username | PersonDataCollectionPolicies.Email
                , config.PersonDataCollectionPolicies
                );
            Assert.AreEqual(
                IpAddressCollectionPolicy.CollectAnonymized
                , config.IpAddressCollectionPolicy
                );
        }
Пример #6
0
        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>();
        });
        public void LoadRollbarAppSettingsTest()
        {
            var sever = new Server();

            RollbarInfrastructureConfig config = new RollbarInfrastructureConfig("default=none");

            Assert.IsNull(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Person);
            Assert.IsNull(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server);

            string settingsFolderPath = Path.Combine(Environment.CurrentDirectory, "TestData");

            AppSettingsUtility.LoadAppSettings(config, settingsFolderPath, "appsettings.json");

            // The test data looks like this:
            //===============================
            //"Rollbar": {
            //    "RollbarLoggerConfig": {
            //        "RollbarDestinationOptions": {
            //            "AccessToken": "17965fa5041749b6bf7095a190001ded",
            //            "Environment": "unit-tests"
            //        },
            //        "RollbarDeveloperOptions": {
            //            "Enabled": true,
            //            "LogLevel": "Info"
            //        },
            //        "RollbarPayloadAdditionOptions": {
            //            "Server": {
            //                "Root": "C://Blah/Blah",
            //                "Cpu": "x64"
            //            },
            //            "Person": {
            //                "UserName": "******"
            //            }
            //        },
            //        "RollbarDataSecurityOptions": {
            //            "ScrubFields": [
            //                "ThePassword",
            //                "TheSecret"
            //            ],
            //        "PersonDataCollectionPolicies": "Username, Email",
            //        "IpAddressCollectionPolicy": "CollectAnonymized"
            //        }
            //    },
            //    "RollbarInfrastructureOptions": {
            //        "MaxReportsPerMinute": 160,
            //        "ReportingQueueDepth": 120
            //    }
            //}

            Assert.AreEqual("17965fa5041749b6bf7095a190001ded", config.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken);
            Assert.AreEqual("unit-tests", config.RollbarLoggerConfig.RollbarDestinationOptions.Environment);

            Assert.AreEqual(true, config.RollbarLoggerConfig.RollbarDeveloperOptions.Enabled);
            Assert.AreEqual(ErrorLevel.Info, config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel);

            Assert.AreEqual(160, config.RollbarInfrastructureOptions.MaxReportsPerMinute);
            Assert.AreEqual(120, config.RollbarInfrastructureOptions.ReportingQueueDepth);

            Assert.IsTrue(config.RollbarLoggerConfig.RollbarDataSecurityOptions.ScrubFields.Length >= 2);
            Assert.AreEqual(
                PersonDataCollectionPolicies.Username | PersonDataCollectionPolicies.Email
                , config.RollbarLoggerConfig.RollbarDataSecurityOptions.PersonDataCollectionPolicies
                );
            Assert.AreEqual(
                IpAddressCollectionPolicy.CollectAnonymized
                , config.RollbarLoggerConfig.RollbarDataSecurityOptions.IpAddressCollectionPolicy
                );

            Assert.AreEqual("jbond", config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Person.UserName);
            Assert.IsNotNull(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server);
            Assert.IsTrue(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.ContainsKey("cpu"));
            Assert.IsTrue(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.ContainsKey("root"));
            Assert.IsFalse(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.ContainsKey("Cpu"));
            Assert.IsFalse(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.ContainsKey("Root"));
            Assert.AreEqual(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server["cpu"], config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.Cpu);
            Assert.AreEqual(config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server["root"], config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.Root);
            Assert.AreEqual("x64", config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.Cpu);
            Assert.AreEqual("C://Blah/Blah", config.RollbarLoggerConfig.RollbarPayloadAdditionOptions.Server.Root);
        }