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); AppSettingsUtil.LoadAppSettings(ref 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); }
/// <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); AppSettingsUtil.LoadAppSettings(ref 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); }
/// <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(); AppSettingsUtil.LoadAppSettings(ref config, configuration); TelemetryCollector.Instance.Config.Reconfigure(config); return(config); }
public void LoadRollbarAppSettingsTest() { RollbarConfig config = new RollbarConfig("default=none"); AppSettingsUtil.LoadAppSettings(ref 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 ); }