Ejemplo n.º 1
0
        private static void InitializingSwitch(object sender, InitializingSwitchEventArgs e)
        {
            Switch sw = e.Switch;

            // Ported from https://referencesource.microsoft.com/#System/compmod/system/diagnostics/Switch.cs,173
            SwitchElementsCollection switchSettings = DiagnosticsConfiguration.SwitchSettings;

            if (switchSettings != null)
            {
                SwitchElement mySettings = switchSettings[sw.DisplayName];

                if (mySettings != null)
                {
                    if (mySettings.Value != null)
                    {
                        sw.Value = mySettings.Value;
                    }
                    else
                    {
                        sw.Value = sw.DefaultValue;
                    }

                    TraceUtils.CopyStringDictionary(sw.Attributes, mySettings.Attributes);
                }
            }
        }
        private void SubscribeToSwitch_Initializing(object?sender, InitializingSwitchEventArgs e)
        {
            Switch sw = e.Switch;

            if (sw.DisplayName == "generalSourceSwitch_Error")
            {
                Assert.IsType <SourceSwitch>(sw);
                SourceSwitch sourceSwitch = (SourceSwitch)sw;
                Assert.Equal(TraceLevel.Error.ToString(), sourceSwitch.Level.ToString());

                // Change to critical
                sourceSwitch.Level = SourceLevels.Critical;
            }
        }