コード例 #1
0
            public void WhenNewSettingsApplied_ThenTraceSourceLevelIsSet()
            {
                var setting = new RuntimeSettings();
                setting.Tracing.TraceSources.Add(new TraceSourceSetting("Foo", SourceLevels.Warning));

                this.manager.Raise(x => x.SettingsChanged += null, new ChangedEventArgs<IRuntimeSettings>(new RuntimeSettings(), setting));

                Assert.Equal(SourceLevels.Warning, this.source.Switch.Level);
            }
コード例 #2
0
            public void WhenDisposingMonitor_ThenStopsTrackingChanges()
            {
                var setting = new RuntimeSettings();
                setting.Tracing.TraceSources.Add(new TraceSourceSetting("Foo", SourceLevels.Information));

                this.monitor.Dispose();

                this.manager.Raise(x => x.SettingsChanged += null, new ChangedEventArgs<IRuntimeSettings>(new RuntimeSettings(), setting));

                Assert.Equal(SourceLevels.Off, this.source.Switch.Level);
            }
コード例 #3
0
            public void Initialize()
            {
                this.source = Tracer.Manager.GetSource("Foo");
                this.source.Switch.Level = SourceLevels.Off;

                this.manager = new Mock<ISettingsManager>();

                var setting = new RuntimeSettings();
                setting.Tracing.TraceSources.Add(new TraceSourceSetting("Foo", SourceLevels.Warning));

                this.manager.Setup(x => x.Read()).Returns(setting);

                this.monitor = new TracingSettingsMonitor(this.manager.Object);
            }
コード例 #4
0
            public void WhenNewSettingsApplied_ThenDefaultTraceListenerIsRestored()
            {
                var setting = new RuntimeSettings();
                setting.Tracing.TraceSources.Add(new TraceSourceSetting("Foo", SourceLevels.Information));

                this.manager.Raise(x => x.SettingsChanged += null, new ChangedEventArgs<IRuntimeSettings>(new RuntimeSettings(), setting));

                var source = Tracer.Manager.GetSource("Foo");

                Assert.True(source.Listeners.Cast<TraceListener>().OfType<DefaultTraceListener>().Any());
            }
コード例 #5
0
            public void WhenNewRootDefaultLevelIsApplied_ThenDefaultSourceLevelIsApplied()
            {
                var setting = new RuntimeSettings();
                setting.Tracing.RootSourceLevel = SourceLevels.ActivityTracing;

                this.manager.Raise(x => x.SettingsChanged += null, new ChangedEventArgs<IRuntimeSettings>(new RuntimeSettings(), setting));

                var defaultSource = Tracer.Manager.GetSource(TracingSettings.DefaultRootSourceName);

                Assert.Equal(SourceLevels.ActivityTracing, defaultSource.Switch.Level);
            }
コード例 #6
0
        private static RuntimeSettings ReadSettings(IServiceProvider serviceProvider)
        {
            var store = GetStore(serviceProvider);

            //// TODO: refactor this code to be generic and reflection/typedescritor-based.

            var settings = new RuntimeSettings();

            var tracingRoot = Path.Combine(StoreConstants.RegistrySettingsKeyName, RuntimeSettings, Tracing);
            var sourceNamesRoot = Path.Combine(StoreConstants.RegistrySettingsKeyName, RuntimeSettings, Tracing, SourceNames);

            if (!store.CollectionExists(tracingRoot))
            {
                return settings;
            }

            if (store.PropertyExists(tracingRoot, RootSourceLevel))
            {
                var rootSourceLevel = store.GetString(tracingRoot, RootSourceLevel);

                if (Enum.IsDefined(typeof(SourceLevels), rootSourceLevel))
                {
                    settings.Tracing.RootSourceLevel = (SourceLevels)Enum.Parse(typeof(SourceLevels), rootSourceLevel);
                }
            }

            foreach (var sourceName in store.GetPropertyNames(sourceNamesRoot))
            {
                var value = store.GetString(sourceNamesRoot, sourceName);

                if (Enum.IsDefined(typeof(SourceLevels), value))
                {
                    settings.Tracing.TraceSources.Add(new TraceSourceSetting(sourceName, (SourceLevels)Enum.Parse(typeof(SourceLevels), value)));
                }
                else
                {
                    tracer.Warn(Resources.SettingsManager_InvalidTraceLevel, value, sourceName);
                }
            }

            return settings;
        }