Code:
/ 4.0 / 4.0 / untmp / 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;
///
/// Provides a multi-level switch to enable or disable tracing
/// and debug output for a compiled application or framework.
///
[SwitchLevel(typeof(TraceLevel))]
public class TraceSwitch : Switch {
///
/// Initializes a new instance of the class.
///
public TraceSwitch(string displayName, string description)
: base(displayName, description) {
}
public TraceSwitch(string displayName, string description, string defaultSwitchValue)
: base(displayName, description, defaultSwitchValue) { }
///
/// Gets or sets the trace
/// level that specifies what messages to output for tracing and debugging.
///
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 a value
/// indicating whether the is set to
/// , , , or
/// .
///
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
/// .
///
public bool TraceVerbose {
get {
return (Level == TraceLevel.Verbose);
}
}
///
///
/// Update the level for this switch.
///
///
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HostedHttpTransportManager.cs
- KeyValueInternalCollection.cs
- WebExceptionStatus.cs
- ISFTagAndGuidCache.cs
- CfgParser.cs
- Subtree.cs
- MailDefinition.cs
- FigureHelper.cs
- EdmConstants.cs
- ManifestSignedXml.cs
- ExtendedProperty.cs
- ParameterCollection.cs
- ValidationError.cs
- BuildManager.cs
- OdbcEnvironmentHandle.cs
- GrammarBuilderPhrase.cs
- WebPartDisplayModeCancelEventArgs.cs
- CommandBinding.cs
- SafeMemoryMappedViewHandle.cs
- SimpleExpression.cs
- LinqExpressionNormalizer.cs
- RIPEMD160.cs
- SystemFonts.cs
- TextDataBindingHandler.cs
- RuleInfoComparer.cs
- PtsPage.cs
- SspiSecurityTokenParameters.cs
- FrameDimension.cs
- MatrixAnimationBase.cs
- DataControlFieldHeaderCell.cs
- ListMarkerSourceInfo.cs
- ToolStripOverflowButton.cs
- SymbolType.cs
- MimeWriter.cs
- ChangeInterceptorAttribute.cs
- RegexCaptureCollection.cs
- _TLSstream.cs
- CapabilitiesSection.cs
- TextComposition.cs
- XmlChildNodes.cs
- HashCodeCombiner.cs
- EntityDataSourceContextDisposingEventArgs.cs
- Menu.cs
- BasicHttpMessageSecurity.cs
- Byte.cs
- InputScopeNameConverter.cs
- MimeMapping.cs
- GridViewRow.cs
- RelationshipWrapper.cs
- GroupStyle.cs
- DataRelation.cs
- securitycriticaldataClass.cs
- CompilationSection.cs
- IndexerNameAttribute.cs
- MexTcpBindingCollectionElement.cs
- Roles.cs
- ProxyAttribute.cs
- XmlSchemaValidationException.cs
- SQLCharsStorage.cs
- DetailsViewInsertEventArgs.cs
- DataBindingExpressionBuilder.cs
- EdgeProfileValidation.cs
- XmlTextReaderImplHelpers.cs
- SqlRetyper.cs
- TypedDataSetSchemaImporterExtension.cs
- TypeForwardedToAttribute.cs
- LocalizedNameDescriptionPair.cs
- SymmetricKeyWrap.cs
- OpenFileDialog.cs
- documentsequencetextview.cs
- HwndProxyElementProvider.cs
- KeyGesture.cs
- MappingItemCollection.cs
- MouseBinding.cs
- ScaleTransform.cs
- TdsValueSetter.cs
- XmlWriterTraceListener.cs
- FlowDocumentReaderAutomationPeer.cs
- RSAOAEPKeyExchangeFormatter.cs
- StorageInfo.cs
- RMEnrollmentPage2.cs
- altserialization.cs
- ProfileSection.cs
- TriggerActionCollection.cs
- SingleAnimationBase.cs
- NavigateUrlConverter.cs
- ThreadExceptionEvent.cs
- GroupBoxRenderer.cs
- SmiEventStream.cs
- TdsParser.cs
- VectorAnimationUsingKeyFrames.cs
- Page.cs
- TreeView.cs
- WinFormsUtils.cs
- LookupBindingPropertiesAttribute.cs
- CategoryGridEntry.cs
- LinkUtilities.cs
- SortQuery.cs
- ItemDragEvent.cs
- ExpressionVisitorHelpers.cs