Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / Diagnostics / TraceSwitch.cs / 1305376 / TraceSwitch.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Diagnostics { using System; using System.ComponentModel; using System.Security; using System.Security.Permissions; ////// [SwitchLevel(typeof(TraceLevel))] public class TraceSwitch : Switch { ///Provides a multi-level switch to enable or disable tracing /// and debug output for a compiled application or framework. ////// public TraceSwitch(string displayName, string description) : base(displayName, description) { } public TraceSwitch(string displayName, string description, string defaultSwitchValue) : base(displayName, description, defaultSwitchValue) { } ///Initializes a new instance of the ///class. /// public TraceLevel Level { get { return (TraceLevel)SwitchSetting; } [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] set { if (value < TraceLevel.Off || value > TraceLevel.Verbose) throw new ArgumentException(SR.GetString(SR.TraceSwitchInvalidLevel)); SwitchSetting = (int)value; } } ///Gets or sets the trace /// level that specifies what messages to output for tracing and debugging. ////// public bool TraceError { get { return (Level >= TraceLevel.Error); } } ///Gets a value /// indicating whether the ///is set to /// , , , or /// . /// public bool TraceWarning { get { return (Level >= TraceLevel.Warning); } } ///Gets a value /// indicating whether the ///is set to /// , , or . /// public bool TraceInfo { get { return (Level >= TraceLevel.Info); } } ///Gets a value /// indicating whether the ///is set to /// or . /// public bool TraceVerbose { get { return (Level == TraceLevel.Verbose); } } ///Gets a value /// indicating whether the ///is set to /// . /// protected override void OnSwitchSettingChanged() { int level = SwitchSetting; if (level < (int)TraceLevel.Off) { Trace.WriteLine(SR.GetString(SR.TraceSwitchLevelTooLow, DisplayName)); SwitchSetting = (int)TraceLevel.Off; } else if (level > (int)TraceLevel.Verbose) { Trace.WriteLine(SR.GetString(SR.TraceSwitchLevelTooHigh, DisplayName)); SwitchSetting = (int)TraceLevel.Verbose; } } protected override void OnValueChanged() { SwitchSetting = (int) Enum.Parse(typeof(TraceLevel), Value, true); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// Update the level for this switch. /// ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Diagnostics { using System; using System.ComponentModel; using System.Security; using System.Security.Permissions; ////// [SwitchLevel(typeof(TraceLevel))] public class TraceSwitch : Switch { ///Provides a multi-level switch to enable or disable tracing /// and debug output for a compiled application or framework. ////// public TraceSwitch(string displayName, string description) : base(displayName, description) { } public TraceSwitch(string displayName, string description, string defaultSwitchValue) : base(displayName, description, defaultSwitchValue) { } ///Initializes a new instance of the ///class. /// public TraceLevel Level { get { return (TraceLevel)SwitchSetting; } [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] set { if (value < TraceLevel.Off || value > TraceLevel.Verbose) throw new ArgumentException(SR.GetString(SR.TraceSwitchInvalidLevel)); SwitchSetting = (int)value; } } ///Gets or sets the trace /// level that specifies what messages to output for tracing and debugging. ////// public bool TraceError { get { return (Level >= TraceLevel.Error); } } ///Gets a value /// indicating whether the ///is set to /// , , , or /// . /// public bool TraceWarning { get { return (Level >= TraceLevel.Warning); } } ///Gets a value /// indicating whether the ///is set to /// , , or . /// public bool TraceInfo { get { return (Level >= TraceLevel.Info); } } ///Gets a value /// indicating whether the ///is set to /// or . /// public bool TraceVerbose { get { return (Level == TraceLevel.Verbose); } } ///Gets a value /// indicating whether the ///is set to /// . /// protected override void OnSwitchSettingChanged() { int level = SwitchSetting; if (level < (int)TraceLevel.Off) { Trace.WriteLine(SR.GetString(SR.TraceSwitchLevelTooLow, DisplayName)); SwitchSetting = (int)TraceLevel.Off; } else if (level > (int)TraceLevel.Verbose) { Trace.WriteLine(SR.GetString(SR.TraceSwitchLevelTooHigh, DisplayName)); SwitchSetting = (int)TraceLevel.Verbose; } } protected override void OnValueChanged() { SwitchSetting = (int) Enum.Parse(typeof(TraceLevel), Value, true); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// Update the level for this switch. /// ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SerializerWriterEventHandlers.cs
- SqlLiftIndependentRowExpressions.cs
- Socket.cs
- XPathNavigatorKeyComparer.cs
- XmlTextReader.cs
- BuildProviderCollection.cs
- __FastResourceComparer.cs
- TextMarkerSource.cs
- TypeSystem.cs
- ToolStripStatusLabel.cs
- WebPartHelpVerb.cs
- StringReader.cs
- TriState.cs
- DependencyProperty.cs
- MouseEvent.cs
- FastPropertyAccessor.cs
- DataContractSerializerSection.cs
- ParserContext.cs
- EntityContainerAssociationSetEnd.cs
- CommunicationObjectAbortedException.cs
- PropertyInformation.cs
- TextTreeDeleteContentUndoUnit.cs
- BaseValidatorDesigner.cs
- AttributeCollection.cs
- ToolStripContentPanelRenderEventArgs.cs
- XmlSchemaSequence.cs
- ZipIOExtraFieldElement.cs
- UnicodeEncoding.cs
- Span.cs
- MetadataItem.cs
- Invariant.cs
- SiteMapNodeItemEventArgs.cs
- Menu.cs
- SequentialOutput.cs
- SHA512Cng.cs
- ExtensionSimplifierMarkupObject.cs
- serverconfig.cs
- PenLineJoinValidation.cs
- Overlapped.cs
- PropertyChangingEventArgs.cs
- SafeNativeMethods.cs
- ValidatorCollection.cs
- AuthenticationService.cs
- ClassHandlersStore.cs
- DataGridViewLayoutData.cs
- StructuredTypeEmitter.cs
- Oci.cs
- ContextStaticAttribute.cs
- StickyNoteAnnotations.cs
- IChannel.cs
- LZCodec.cs
- KeyboardDevice.cs
- ReadOnlyMetadataCollection.cs
- XmlSchemaSimpleType.cs
- Baml6Assembly.cs
- ExecutionContext.cs
- IndependentlyAnimatedPropertyMetadata.cs
- EnglishPluralizationService.cs
- TypeInitializationException.cs
- CommonGetThemePartSize.cs
- SchemaUtility.cs
- GridViewEditEventArgs.cs
- ServiceDocumentFormatter.cs
- XmlAttributeHolder.cs
- StorageEndPropertyMapping.cs
- SchemaElementLookUpTable.cs
- WsiProfilesElementCollection.cs
- EntityDataSourceWrapperCollection.cs
- TokenizerHelper.cs
- Unit.cs
- DataFormats.cs
- RenderCapability.cs
- DocumentEventArgs.cs
- AuthorizationPolicyTypeElementCollection.cs
- FilteredAttributeCollection.cs
- ParameterBuilder.cs
- WeakRefEnumerator.cs
- SqlReorderer.cs
- EffectiveValueEntry.cs
- StrongName.cs
- ListViewPagedDataSource.cs
- OracleConnectionFactory.cs
- MemberCollection.cs
- WeakHashtable.cs
- SequenceFullException.cs
- SolidBrush.cs
- TypeDependencyAttribute.cs
- UIPermission.cs
- TextTabProperties.cs
- FormViewModeEventArgs.cs
- KeyTime.cs
- SHA384.cs
- AutomationProperties.cs
- ParserStreamGeometryContext.cs
- CustomErrorCollection.cs
- PackWebRequestFactory.cs
- HtmlInputCheckBox.cs
- XPathBuilder.cs
- ServicesSection.cs
- BoolLiteral.cs