示例#1
0
        public async Task LoggerSettings()
        {
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest");

            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-LogLevel", AmbientLogLevel.Error.ToString());
            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-TypeFilter", "AllowedLoggerType");
            settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-CategoryFilter", "AllowedCategory");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> o = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet))
            {
                AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>();
                logger.Log(new ApplicationException());

                AmbientLogger <TestLogger> testlogger = new AmbientLogger <TestLogger>();
                testlogger.Log(new ApplicationException());
                testlogger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("test message");
                testlogger.Log(() => "test message");
                testlogger.Log("test message", "category", AmbientLogLevel.Information);
                testlogger.Log("test message", "AllowedCategory", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException());
                testlogger.Log(() => "Exception during test", new ApplicationException());
                testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
                testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);

                if (_Logger.Local != null)
                {
                    await _Logger.Local.Flush();
                }
            }
        }
示例#2
0
 public void SettingsSetWithExtraSettings()
 {
     Dictionary <string, string> settings = new Dictionary <string, string> {
         { nameof(SettingsSetWithExtraSettings) + "1", null }, { nameof(SettingsSetWithExtraSettings) + "2", "test" },
     };
     IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetWithExtraSettings), settings);
 }
示例#3
0
        public async Task LoggerExplicitSettings()
        {
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest");

            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-LogLevel", AmbientLogLevel.Error.ToString());
            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-TypeBlock", ".*[Bb]lock.*");
            settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-CategoryBlock", ".*[Bb]lock.*");
            AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>(_Logger.Global, settingsSet);

            logger.Log(new ApplicationException());
            logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("test message");
            logger.Log(() => "test message");
            logger.Log("test message", "category", AmbientLogLevel.Information);
            logger.Log("test message", "AllowedCategory", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException());
            logger.Log(() => "Exception during test", new ApplicationException());
            logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information);
            logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information);
            if (_Logger.Global != null)
            {
                await _Logger.Global.Flush();
            }
        }
示例#4
0
        public void AmbientSettingInt()
        {
            // use a local override in case we ran another test that left the global or local settings set set to something else on this thread
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(AmbientSettingInt));

            using (ScopedLocalServiceOverride <IAmbientSettingsSet> localOverrideTest = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settings))
            {
                AmbientSetting <int> value;
                value = new AmbientSetting <int>("int-setting", "", s => string.IsNullOrEmpty(s) ? 0 : Int32.Parse(s));
                Assert.AreEqual(0, value.Value);
                value = new AmbientSetting <int>("int-setting-2", "", s => Int32.Parse(s), "1");
                Assert.AreEqual(1, value.Value);
                value = new AmbientSetting <int>("int-setting-3", "", s => Int32.Parse(s), "1");
                Assert.AreEqual(1, value.Value);

                // test changing the setting without an event listener
                settings.ChangeSetting("int-setting-3", "5");
                // test changing the setting to the same value without an event listener
                settings.ChangeSetting("int-setting-3", "5");
                // test changing the setting to null so we fall through to the global settings set
                settings.ChangeSetting("int-setting-3", null);
                int settingValue = value.Value;
                Assert.AreEqual(1, value.Value);
            }
        }
示例#5
0
        public void SettingLocalChangeSettingsSet()
        {
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingLocalChangeSettingsSet));

            using (new ScopedLocalServiceOverride <IMutableAmbientSettingsSet>(settingsSet))
                using (new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet))
                {
                    string testSettingKey               = nameof(SettingLocalChangeSettingsSet);
                    string initialValue                 = "initialValue";
                    string notificationNewValue         = "";
                    AmbientSetting <string> testSetting = new AmbientSetting <string>(testSettingKey, "", s => { notificationNewValue = s; return(s); }, initialValue);
                    Assert.AreEqual(initialValue, testSetting.Value);
                    Assert.AreEqual(initialValue, notificationNewValue);

                    // now switch local settings set and try again
                    string secondValue = "change1";
                    IMutableAmbientSettingsSet settingsSet2 = new BasicAmbientSettingsSet(nameof(SettingLocalChangeSettingsSet) + "_2");
                    using (new ScopedLocalServiceOverride <IMutableAmbientSettingsSet>(settingsSet2))
                        using (new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet2))
                        {
                            settingsSet2.ChangeSetting(testSettingKey, secondValue);
                            Assert.AreEqual(secondValue, testSetting.Value);
                            Assert.AreEqual(secondValue, notificationNewValue);
                        }
                }
        }
示例#6
0
        public void SettingsSetSettingNonStringNullConvert()
        {
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetSettingNonStringNullConvert));
            string testSettingKey = nameof(SettingsSetSettingNonStringNullConvert);

            Assert.ThrowsException <ArgumentNullException>(() => new SettingsSetSetting <int>(settingsSet, testSettingKey, "", null, "1"));
            Assert.ThrowsException <ArgumentNullException>(() => new SettingsSetSetting <int>(settingsSet, testSettingKey, "", 1, null));
            Assert.ThrowsException <ArgumentNullException>(() => new SettingsSetSetting <int?>(settingsSet, testSettingKey, "", (int?)null, null));
        }
示例#7
0
        public void SettingsSetGetRawValue()
        {
            Dictionary <string, string> settings = new Dictionary <string, string> {
                { nameof(SettingsSetGetRawValue), "1" },
            };
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetGetRawValue), settings);

            Assert.AreEqual(null, settingsSet.GetRawValue(nameof(SettingsSetGetRawValue) + "-notfound"));
            Assert.AreEqual("1", settingsSet.GetRawValue(nameof(SettingsSetGetRawValue)));
        }
示例#8
0
 public void SettingsSetWithPreregisteredSettings()
 {
     SettingInfo <string>        base1    = new SettingInfo <string>(nameof(SettingsSetWithPreregisteredSettings) + "1", "", null);
     SettingInfo <int>           base2    = new SettingInfo <int>(nameof(SettingsSetWithPreregisteredSettings) + "2", "", s => string.IsNullOrEmpty(s) ? 2 : Int32.Parse(s));
     SettingInfo <int>           base3    = new SettingInfo <int>(nameof(SettingsSetWithPreregisteredSettings) + "3", "", s => Int32.Parse(s), "3");
     Dictionary <string, string> settings = new Dictionary <string, string> {
         { nameof(SettingsSetWithPreregisteredSettings) + "1", null }, { nameof(SettingsSetWithPreregisteredSettings) + "2", "2" }, { nameof(SettingsSetWithPreregisteredSettings) + "3", null },
     };
     IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetWithPreregisteredSettings), settings);
 }
        public void AmbientServiceProfilerCoordinatorSettingsNonCurrent()
        {
            string system1 = "DynamoDB/Table:My-table/Partition:342644/Result:Success";
            string system2 = "S3/Bucket:My-bucket/Prefix:abcdefg/Result:Retry";
            string system3 = "SQL/Database:My-database/Table:User/Result:Failed";
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(AmbientServiceProfilerCoordinatorSettingsNonCurrent));

            settingsSet.ChangeSetting(nameof(AmbientServiceProfilerCoordinator) + "-DefaultSystemGroupTransform", "(?:([^:/]+)(?:(/Database:[^:/]*)|(/Bucket:[^:/]*)|(/Result:[^:/]*)|(?:/[^/]*))*)");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> o = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet))
                using (ScopedLocalServiceOverride <IAmbientServiceProfiler> p = new ScopedLocalServiceOverride <IAmbientServiceProfiler>(new BasicAmbientServiceProfiler()))
                    using (AmbientClock.Pause())
                        using (AmbientServiceProfilerCoordinator coordinator = new AmbientServiceProfilerCoordinator())
                            using (IAmbientServiceProfile scopeProfile = coordinator.CreateCallContextProfiler(nameof(ServiceProfilerBasic)))
                            {
                                _ServiceProfiler.Local?.SwitchSystem(system1);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(5));

                                _ServiceProfiler.Local?.SwitchSystem(system2);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(200));

                                _ServiceProfiler.Local?.SwitchSystem(system3);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(3000));

                                _ServiceProfiler.Local?.SwitchSystem(system1);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(5));

                                _ServiceProfiler.Local?.SwitchSystem("noreport");

                                if (scopeProfile != null)
                                {
                                    foreach (AmbientServiceProfilerAccumulator stats in scopeProfile.ProfilerStatistics)
                                    {
                                        if (stats.Group.StartsWith("DynamoDB"))
                                        {
                                            Assert.AreEqual("DynamoDB/Result:Success", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(10), stats.TimeUsed);
                                            Assert.AreEqual(2, stats.ExecutionCount);
                                        }
                                        else if (stats.Group.StartsWith("S3"))
                                        {
                                            Assert.AreEqual("S3/Bucket:My-bucket/Result:Retry", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(200), stats.TimeUsed);
                                            Assert.AreEqual(1, stats.ExecutionCount);
                                        }
                                        else if (stats.Group.StartsWith("SQL"))
                                        {
                                            Assert.AreEqual("SQL/Database:My-database/Result:Failed", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(3000), stats.TimeUsed);
                                            Assert.AreEqual(1, stats.ExecutionCount);
                                        }
                                    }
                                }
                            }
        }
示例#10
0
        public void SettingMisc()
        {
            Dictionary <string, string> settings = new Dictionary <string, string>()
            {
                { "key", "value" }
            };
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingMisc), settings);

            Assert.IsTrue(settingsSet !.ToString() !.Contains(nameof(SettingMisc)));
            Assert.AreEqual("SettingMisc", settingsSet.SetName);
        }
        public async Task StatusAuditorHistory()
        {
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(StatusAuditorHistory));

            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionMinutes", "5");
            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionEntries", "10");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> localOverrideTest = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settings))

                using (AmbientClock.Pause())
                {
                    using (StatusAuditorTest test = new StatusAuditorTest(nameof(StatusAuditorTest)))
                    {
                        StatusResults results = await test.GetStatus();

                        Assert.AreEqual("StatusAuditorTest", test.TargetSystem);
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // since we're rotating the status rating, the frequency will vary because of that
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one starts kicking out history items due to count (this was determined by simply trying it out, but that part doesn't matter for this test)
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one should start kicking history items out due to time
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                    }
                }
        }
示例#12
0
        public void SettingsGarbageCollection()
        {
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsGarbageCollection));
            string testSettingKey = nameof(SettingsGarbageCollection);
            WeakReference <SettingsSetSetting <string> > wr = FinalizableSetting(testSettingKey, settingsSet);

            GC.Collect();                                                                                   // this should collect the temporary Setting created in the function below
            settingsSet.ChangeSetting(testSettingKey, nameof(SettingsGarbageCollection) + "-CauseCollect"); // this should cause the weak proxy to get removed and the instance to be destroyed
            SettingsSetSetting <string> alive;

            Assert.IsFalse(wr.TryGetTarget(out alive));
        }
示例#13
0
        public void SettingsSetSettingChangeNoNotification()
        {
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetSettingChangeNoNotification));
            string testSettingKey = nameof(SettingsSetSettingChangeNoNotification);
            string initialValue   = "initialValue";
            SettingsSetSetting <string> testSetting = new SettingsSetSetting <string>(settingsSet, testSettingKey, "", s => s, initialValue);

            Assert.AreEqual(initialValue, testSetting.Value);
            string secondValue = "change1";

            settingsSet.ChangeSetting(testSettingKey, secondValue);
            Assert.AreEqual(secondValue, testSetting.Value);
        }
示例#14
0
        public void LogFilterTypeCategoryBlock()
        {
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(LogFilterTypeCategoryBlock));

            settings.ChangeSetting(nameof(LogFilterTypeCategoryBlock) + "-" + nameof(AmbientLogFilter) + "-LogLevel", AmbientLogLevel.Information.ToString());
            settings.ChangeSetting(nameof(LogFilterTypeCategoryBlock) + "-" + nameof(AmbientLogFilter) + "-TypeAllow", null);
            settings.ChangeSetting(nameof(LogFilterTypeCategoryBlock) + "-" + nameof(AmbientLogFilter) + "-TypeBlock", ".*[Bb]lock.*");
            settings.ChangeSetting(nameof(LogFilterTypeCategoryBlock) + "-" + nameof(AmbientLogFilter) + "-CategoryAllow", null);
            settings.ChangeSetting(nameof(LogFilterTypeCategoryBlock) + "-" + nameof(AmbientLogFilter) + "-CategoryBlock", ".*[Bb]lock.*");
            AmbientLogFilter filter = new AmbientLogFilter(nameof(LogFilterTypeCategoryBlock), settings);

            Assert.AreEqual(AmbientLogLevel.Information, filter.LogLevel);
            Assert.IsFalse(filter.IsTypeBlocked("test"));
            Assert.IsTrue(filter.IsTypeBlocked("testblock"));
            Assert.IsFalse(filter.IsCategoryBlocked("test"));
            Assert.IsTrue(filter.IsCategoryBlocked("testblock"));
        }
示例#15
0
        public void SettingsSetSettingsWithSetName()
        {
            string settingName = nameof(SettingsSetSettingsWithSetName) + "-int-setting";

            IAmbientSetting <int> setting = AmbientSettings.GetSettingsSetSetting(null, settingName, "", s => Int32.Parse(s), "1");

            Assert.AreEqual(1, setting.Value);
            Assert.IsNotNull(setting.GetValueWithSetName().Item2);

            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(SettingsSetSettingsWithSetName));

            setting = AmbientSettings.GetSettingsSetSetting(settings, settingName, "", s => Int32.Parse(s), "1");
            Assert.AreEqual(1, setting.Value);
            Assert.IsNotNull(setting.GetValueWithSetName().Item2);

            settings.ChangeSetting(settingName, "2");
            Assert.AreEqual(2, setting.Value);
            Assert.AreEqual(nameof(SettingsSetSettingsWithSetName), setting.GetValueWithSetName().Item2);
        }
示例#16
0
        public void SettingsSetSettingNullConvert()
        {
            IMutableAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(SettingsSetSettingNullConvert));
            string testSettingKey = nameof(SettingsSetSettingNullConvert);
            string initialValue   = "initialValue";
            string secondValue    = "change1";
            SettingsSetSetting <string> testSetting = new SettingsSetSetting <string>(settingsSet, testSettingKey, "", null, initialValue);

            Assert.AreEqual(initialValue, testSetting.Value);
            settingsSet.ChangeSetting(testSettingKey, secondValue);
            Assert.AreEqual(secondValue, testSetting.Value);
            settingsSet.ChangeSetting(testSettingKey, initialValue);
            Assert.AreEqual(initialValue, testSetting.Value);
            testSetting = new SettingsSetSetting <string>(settingsSet, testSettingKey, "", initialValue, null);
            Assert.AreEqual(initialValue, testSetting.Value);
            settingsSet.ChangeSetting(testSettingKey, secondValue);
            Assert.AreEqual(secondValue, testSetting.Value);
            settingsSet.ChangeSetting(testSettingKey, initialValue);
            Assert.AreEqual(initialValue, testSetting.Value);
        }
示例#17
0
        public void AmbientSettingsWithSetName()
        {
            string settingName            = nameof(AmbientSettingsWithSetName) + "-int-setting";
            AmbientSetting <int> setting3 = new AmbientSetting <int>(settingName, "", s => Int32.Parse(s), "1");

            Assert.AreEqual(1, setting3.Value);
            Assert.IsNotNull(setting3.GetValueWithSetName().Item2);
            IMutableAmbientSettingsSet settingsSet = _SettingsSet.Global as IMutableAmbientSettingsSet;

            if (settingsSet != null)
            {
                settingsSet.ChangeSetting(settingName, "2");
                Assert.AreEqual(2, setting3.Value);
                Assert.AreEqual(BasicAmbientSettingsSet.DefaultSetName, setting3.GetValueWithSetName().Item2);
            }
            // use a local override in case we ran another test that left the global or local settings set set to something else on this thread
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(AmbientSettingsWithSetName));

            using (ScopedLocalServiceOverride <IAmbientSettingsSet> localOverrideTest = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settings))
            {
                AmbientSetting <int> setting;
                setting = new AmbientSetting <int>(nameof(AmbientSettingsWithSetName) + "-int-setting-1", "", s => string.IsNullOrEmpty(s) ? 0 : Int32.Parse(s));
                Assert.AreEqual(0, setting.Value);
                Assert.IsNotNull(setting.GetValueWithSetName().Item2);
                setting = new AmbientSetting <int>(nameof(AmbientSettingsWithSetName) + "-int-setting-2", "", s => Int32.Parse(s), "1");
                settings.ChangeSetting(nameof(AmbientSettingsWithSetName) + "-int-setting-2", "1");
                Assert.AreEqual(1, setting.Value);
                Assert.AreEqual(nameof(AmbientSettingsWithSetName), setting.GetValueWithSetName().Item2);
                setting = new AmbientSetting <int>(settingName, "", s => Int32.Parse(s), "1");
                settings.ChangeSetting(settingName, "3");
                Assert.AreEqual(3, setting3.Value);
                Assert.AreEqual(nameof(AmbientSettingsWithSetName), setting3.GetValueWithSetName().Item2);

                // test changing the setting to null so we fall through to the global settings set
                settings.ChangeSetting(settingName, null);
                int settingValue = setting.Value;
                Assert.AreEqual(1, setting.Value);
                Assert.IsNotNull(setting3.GetValueWithSetName().Item2);
            }
        }
示例#18
0
        public void LogFilterBlock()
        {
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(LogFilterBlock));

            settings.ChangeSetting(nameof(LogFilterBlock) + "-" + nameof(AmbientLogFilter) + "-LogLevel", AmbientLogLevel.Information.ToString());
            settings.ChangeSetting(nameof(LogFilterBlock) + "-" + nameof(AmbientLogFilter) + "-TypeBlock", ".*[Bb]lock.*");
            settings.ChangeSetting(nameof(LogFilterBlock) + "-" + nameof(AmbientLogFilter) + "-CategoryBlock", ".*[Bb]lock.*");
            AmbientLogFilter filter = new AmbientLogFilter(nameof(LogFilterBlock), settings);

            Assert.IsFalse(filter.IsBlocked(AmbientLogLevel.Information, "test", "test"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "test", "test"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Information, "testBlock", "test"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "testBlock", "test"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Information, "test", "testBlock"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "test", "testBlock"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Information, "testBlock", "testBlock"));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "testBlock", "testBlock"));

            Assert.IsFalse(filter.IsBlocked(AmbientLogLevel.Information, "test", null));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "test", null));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Information, "testBlock", null));
            Assert.IsTrue(filter.IsBlocked(AmbientLogLevel.Trace, "testBlock", null));
        }