Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / BCL / System / BCLDebug.cs / 1 / BCLDebug.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: BCLDebug
**
**
** Purpose: Debugging Macros for use in the Base Class Libraries
**
**
============================================================*/
namespace System {
using System.IO;
using System.Text;
using System.Runtime.Remoting;
using System.Diagnostics;
using Microsoft.Win32;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Security;
[Serializable]
internal enum LogLevel {
Trace = 0,
Status = 20,
Warning= 40,
Error = 50,
Panic = 100,
}
internal struct SwitchStructure {
internal String name;
internal int value;
internal SwitchStructure (String n, int v) {
name = n;
value = v;
}
}
// Only statics, does not need to be marked with the serializable attribute
internal static class BCLDebug {
internal static bool m_registryChecked=false;
internal static bool m_loggingNotEnabled = false;
internal static bool m_perfWarnings;
internal static bool m_correctnessWarnings;
internal static bool m_safeHandleStackTraces;
#if _DEBUG
internal static bool m_domainUnloadAdded;
#endif
internal static PermissionSet m_MakeConsoleErrorLoggingWork;
static readonly SwitchStructure[] switches = {
new SwitchStructure("NLS", 0x00000001),
new SwitchStructure("SER", 0x00000002),
new SwitchStructure("DYNIL",0x00000004),
new SwitchStructure("REMOTE",0x00000008),
new SwitchStructure("BINARY",0x00000010), //Binary Formatter
new SwitchStructure("SOAP",0x00000020), // Soap Formatter
new SwitchStructure("REMOTINGCHANNELS",0x00000040),
new SwitchStructure("CACHE",0x00000080),
new SwitchStructure("RESMGRFILEFORMAT", 0x00000100), // .resources files
new SwitchStructure("PERF", 0x00000200),
new SwitchStructure("CORRECTNESS", 0x00000400),
new SwitchStructure("MEMORYFAILPOINT", 0x00000800),
};
static readonly LogLevel[] levelConversions = {
LogLevel.Panic,
LogLevel.Error,
LogLevel.Error,
LogLevel.Warning,
LogLevel.Warning,
LogLevel.Status,
LogLevel.Status,
LogLevel.Trace,
LogLevel.Trace,
LogLevel.Trace,
LogLevel.Trace
};
#if _DEBUG
internal static void WaitForFinalizers(Object sender, EventArgs e)
{
if (!m_registryChecked) {
CheckRegistry();
}
if (m_correctnessWarnings) {
GC.GetTotalMemory(true);
GC.WaitForPendingFinalizers();
}
}
#endif
[Conditional("_DEBUG")]
[ResourceExposure(ResourceScope.None)]
static public void Assert(bool condition, String message) {
#if _DEBUG
// Speed up debug builds marginally by avoiding the garbage from
// concatinating "BCL Assert: " and the message.
if (!condition)
System.Diagnostics.Assert.Check(condition, "BCL Assert", message);
#endif
}
[Conditional("_LOGGING")]
static public void Log(String message) {
if (AppDomain.CurrentDomain.IsUnloadingForcedFinalize())
return;
if (!m_registryChecked) {
CheckRegistry();
}
System.Diagnostics.Log.Trace(message);
System.Diagnostics.Log.Trace(Environment.NewLine);
}
[Conditional("_LOGGING")]
static public void Log(String switchName, String message) {
if (AppDomain.CurrentDomain.IsUnloadingForcedFinalize())
return;
if (!m_registryChecked) {
CheckRegistry();
}
try {
LogSwitch ls;
ls = LogSwitch.GetSwitch(switchName);
if (ls!=null) {
System.Diagnostics.Log.Trace(ls,message);
System.Diagnostics.Log.Trace(ls,Environment.NewLine);
}
} catch {
System.Diagnostics.Log.Trace("Exception thrown in logging." + Environment.NewLine);
System.Diagnostics.Log.Trace("Switch was: " + ((switchName==null)?"":switchName) + Environment.NewLine);
System.Diagnostics.Log.Trace("Message was: " + ((message==null)?"":message) + Environment.NewLine);
}
}
//
// This code gets called during security startup, so we can't go through Marshal to get the values. This is
// just a small helper in native code instead of that.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static int GetRegistryLoggingValues(out bool loggingEnabled, out bool logToConsole, out int logLevel, out bool perfWarnings, out bool correctnessWarnings, out bool safeHandleStackTraces);
private static void CheckRegistry() {
if (AppDomain.CurrentDomain.IsUnloadingForcedFinalize())
return;
if (m_registryChecked) {
return;
}
m_registryChecked = true;
bool loggingEnabled;
bool logToConsole;
int logLevel;
int facilityValue;
facilityValue = GetRegistryLoggingValues(out loggingEnabled, out logToConsole, out logLevel, out m_perfWarnings, out m_correctnessWarnings, out m_safeHandleStackTraces);
// Note we can get into some recursive situations where we call
// ourseves recursively through the .cctor. That's why we have the
// check for levelConversions == null.
if (!loggingEnabled) {
m_loggingNotEnabled = true;
}
if (loggingEnabled && levelConversions!=null) {
try {
//The values returned for the logging levels in the registry don't map nicely onto the
//values which we support internally (which are an approximation of the ones that
//the System.Diagnostics namespace uses) so we have a quick map.
Assert(logLevel>=0 && logLevel<=10, "logLevel>=0 && logLevel<=10");
logLevel = (int)levelConversions[logLevel];
if (facilityValue>0) {
for (int i=0; i":switchName) + Environment.NewLine);
System.Diagnostics.Log.Trace("Message was: " + ((message==null)?"":message) + Environment.NewLine);
}
}
//
// This code gets called during security startup, so we can't go through Marshal to get the values. This is
// just a small helper in native code instead of that.
//
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static int GetRegistryLoggingValues(out bool loggingEnabled, out bool logToConsole, out int logLevel, out bool perfWarnings, out bool correctnessWarnings, out bool safeHandleStackTraces);
private static void CheckRegistry() {
if (AppDomain.CurrentDomain.IsUnloadingForcedFinalize())
return;
if (m_registryChecked) {
return;
}
m_registryChecked = true;
bool loggingEnabled;
bool logToConsole;
int logLevel;
int facilityValue;
facilityValue = GetRegistryLoggingValues(out loggingEnabled, out logToConsole, out logLevel, out m_perfWarnings, out m_correctnessWarnings, out m_safeHandleStackTraces);
// Note we can get into some recursive situations where we call
// ourseves recursively through the .cctor. That's why we have the
// check for levelConversions == null.
if (!loggingEnabled) {
m_loggingNotEnabled = true;
}
if (loggingEnabled && levelConversions!=null) {
try {
//The values returned for the logging levels in the registry don't map nicely onto the
//values which we support internally (which are an approximation of the ones that
//the System.Diagnostics namespace uses) so we have a quick map.
Assert(logLevel>=0 && logLevel<=10, "logLevel>=0 && logLevel<=10");
logLevel = (int)levelConversions[logLevel];
if (facilityValue>0) {
for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DesignerAttribute.cs
- CodeDomConfigurationHandler.cs
- WindowsGraphics2.cs
- PointLightBase.cs
- Validator.cs
- SchemaTypeEmitter.cs
- MenuCommand.cs
- ModulesEntry.cs
- ConfigXmlElement.cs
- HttpCacheVaryByContentEncodings.cs
- _UriTypeConverter.cs
- SplineKeyFrames.cs
- Function.cs
- SoapSchemaMember.cs
- UserControlAutomationPeer.cs
- InstanceOwnerQueryResult.cs
- AdapterDictionary.cs
- WmlLinkAdapter.cs
- VScrollBar.cs
- DbDataAdapter.cs
- DataSpaceManager.cs
- HttpModule.cs
- Visual3D.cs
- TypefaceMap.cs
- FacetEnabledSchemaElement.cs
- DynamicPropertyHolder.cs
- _OverlappedAsyncResult.cs
- XmlDictionaryString.cs
- SourceInterpreter.cs
- CaseInsensitiveHashCodeProvider.cs
- HtmlForm.cs
- TdsParserStateObject.cs
- LogLogRecordEnumerator.cs
- GridViewUpdateEventArgs.cs
- UpdateCommand.cs
- SecurityPermission.cs
- DataGridItem.cs
- CompletedAsyncResult.cs
- StoreAnnotationsMap.cs
- ZipIOExtraFieldPaddingElement.cs
- CreateSequenceResponse.cs
- SharedPersonalizationStateInfo.cs
- UrlUtility.cs
- WindowsRichEdit.cs
- Material.cs
- TrueReadOnlyCollection.cs
- ForAllOperator.cs
- DoWorkEventArgs.cs
- HostedTcpTransportManager.cs
- MenuItem.cs
- ActivityInstanceMap.cs
- ComponentResourceKey.cs
- PropertyGroupDescription.cs
- SafeUserTokenHandle.cs
- NameSpaceExtractor.cs
- ItemAutomationPeer.cs
- OleDbRowUpdatingEvent.cs
- TableCellAutomationPeer.cs
- SQLCharsStorage.cs
- WSUtilitySpecificationVersion.cs
- TextRangeAdaptor.cs
- SafeHandle.cs
- SchemeSettingElement.cs
- LoginView.cs
- ProcessHostConfigUtils.cs
- RuntimeHandles.cs
- GridToolTip.cs
- AuthorizationRuleCollection.cs
- ConfigurationManagerInternal.cs
- FormViewUpdatedEventArgs.cs
- InstallerTypeAttribute.cs
- DataBindingList.cs
- ExpressionBindingCollection.cs
- ContainerSelectorBehavior.cs
- CodeTypeMemberCollection.cs
- InfoCardAsymmetricCrypto.cs
- WorkflowPersistenceContext.cs
- EventLogPermissionHolder.cs
- SqlProfileProvider.cs
- _IPv4Address.cs
- FileEnumerator.cs
- BitArray.cs
- CatchDesigner.xaml.cs
- columnmapfactory.cs
- MaterialCollection.cs
- DataGridViewCellCollection.cs
- XmlMemberMapping.cs
- Vector.cs
- EmptyEnumerator.cs
- HtmlUtf8RawTextWriter.cs
- Drawing.cs
- PreloadHost.cs
- MULTI_QI.cs
- ObjectPersistData.cs
- CounterSampleCalculator.cs
- ElementProxy.cs
- Sequence.cs
- HttpCapabilitiesEvaluator.cs
- KeyManager.cs
- HScrollProperties.cs