Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CompMod / System / Diagnostics / TraceSwitch.cs / 1 / 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.
//------------------------------------------------------------------------------
//
// 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
- MailBnfHelper.cs
- SimpleWorkerRequest.cs
- ResXResourceSet.cs
- FileVersion.cs
- InputMethodStateTypeInfo.cs
- GenericsInstances.cs
- Container.cs
- DataBindingList.cs
- ViewDesigner.cs
- RelativeSource.cs
- ImportDesigner.xaml.cs
- QueryResultOp.cs
- VideoDrawing.cs
- TreeNodeConverter.cs
- SessionParameter.cs
- behaviorssection.cs
- MultiTrigger.cs
- ContextStack.cs
- XmlChildNodes.cs
- ConfigXmlComment.cs
- WebPartCancelEventArgs.cs
- SystemResourceHost.cs
- TextAnchor.cs
- Light.cs
- BaseParser.cs
- HttpRequestContext.cs
- DirectoryNotFoundException.cs
- Keyboard.cs
- ObjectListCommand.cs
- ToolStripComboBox.cs
- OrderedDictionaryStateHelper.cs
- designeractionlistschangedeventargs.cs
- CodeDOMUtility.cs
- AssemblyAttributesGoHere.cs
- TextEndOfSegment.cs
- DialogBaseForm.cs
- ComPlusTypeValidator.cs
- HttpWebRequest.cs
- ProfileBuildProvider.cs
- TouchPoint.cs
- NestedContainer.cs
- WebPartConnection.cs
- COM2ExtendedBrowsingHandler.cs
- Content.cs
- LabelAutomationPeer.cs
- PasswordTextNavigator.cs
- RuleSetDialog.Designer.cs
- Model3D.cs
- StateManagedCollection.cs
- TypeUsage.cs
- SelectionManager.cs
- ExclusiveHandleList.cs
- SelectionItemProviderWrapper.cs
- RemoteEndpointMessageProperty.cs
- TypeReference.cs
- DetailsViewRowCollection.cs
- AppDomainFactory.cs
- DataSourceViewSchemaConverter.cs
- IpcClientManager.cs
- SqlConnectionManager.cs
- FilterQuery.cs
- XmlMessageFormatter.cs
- ProvidersHelper.cs
- DesignerForm.cs
- TraceLevelHelper.cs
- SchemaSetCompiler.cs
- ScopeElementCollection.cs
- WebPartsSection.cs
- CodeDomConfigurationHandler.cs
- CustomValidator.cs
- WebHttpElement.cs
- ExpressionTable.cs
- SqlTransaction.cs
- WindowsGraphics2.cs
- XmlEncoding.cs
- PlainXmlSerializer.cs
- SQLUtility.cs
- SchemaEntity.cs
- CheckBoxField.cs
- LinqDataSourceHelper.cs
- CompiledRegexRunnerFactory.cs
- DataGridViewSelectedColumnCollection.cs
- FilterRepeater.cs
- WpfGeneratedKnownTypes.cs
- versioninfo.cs
- dataprotectionpermissionattribute.cs
- PreviewPageInfo.cs
- SettingsProperty.cs
- OletxDependentTransaction.cs
- LineBreak.cs
- PowerEase.cs
- XmlTextReaderImplHelpers.cs
- FullTextLine.cs
- MouseActionValueSerializer.cs
- ModelItemCollectionImpl.cs
- WmlPanelAdapter.cs
- FullTextBreakpoint.cs
- BeginStoryboard.cs
- IdentifierCreationService.cs
- BrushMappingModeValidation.cs