Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / Diagnostics / log.cs / 1 / log.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Diagnostics { using System.Runtime.Remoting; using System; using System.Security.Permissions; using System.IO; using System.Collections; using System.Runtime.CompilerServices; using Encoding = System.Text.Encoding; using System.Runtime.Versioning; // LogMessageEventHandlers are triggered when a message is generated which is // "on" per its switch. // // By default, the debugger (if attached) is the only event handler. // There is also a "built-in" console device which can be enabled // programatically, by registry (specifics....) or environment // variables. [Serializable()] [HostProtection(Synchronization=true, ExternalThreading=true)] internal delegate void LogMessageEventHandler(LoggingLevels level, LogSwitch category, String message, StackTrace location); // LogSwitchLevelHandlers are triggered when the level of a LogSwitch is modified // NOTE: These are NOT triggered when the log switch setting is changed from the // attached debugger. // [Serializable()] internal delegate void LogSwitchLevelHandler(LogSwitch ls, LoggingLevels newLevel); internal static class Log { // Switches allow relatively fine level control of which messages are // actually shown. Normally most debugging messages are not shown - the // user will typically enable those which are relevant to what is being // investigated. // // An attached debugger can enable or disable which messages will // actually be reported to the user through the COM+ debugger // services API. This info is communicated to the runtime so only // desired events are actually reported to the debugger. internal static Hashtable m_Hashtable; private static bool m_fConsoleDeviceEnabled; private static Stream[] m_rgStream; private static int m_iNumOfStreamDevices; private static int m_iStreamArraySize; //private static StreamWriter pConsole; internal static int iNumOfSwitches; //private static int iNumOfMsgHandlers; //private static int iMsgHandlerArraySize; private static LogMessageEventHandler _LogMessageEventHandler; private static LogSwitchLevelHandler _LogSwitchLevelHandler; private static Object locker; // Constant representing the global switch public static readonly LogSwitch GlobalSwitch; static Log() { m_Hashtable = new Hashtable(); m_fConsoleDeviceEnabled = false; m_rgStream = null; m_iNumOfStreamDevices = 0; m_iStreamArraySize = 0; //pConsole = null; //iNumOfMsgHandlers = 0; //iMsgHandlerArraySize = 0; locker = new Object(); // allocate the GlobalSwitch object GlobalSwitch = new LogSwitch ("Global", "Global Switch for this log"); GlobalSwitch.MinimumLevel = LoggingLevels.ErrorLevel; } public static void AddOnLogMessage(LogMessageEventHandler handler) { lock (locker) _LogMessageEventHandler = (LogMessageEventHandler) MulticastDelegate.Combine(_LogMessageEventHandler, handler); } public static void RemoveOnLogMessage(LogMessageEventHandler handler) { lock (locker) _LogMessageEventHandler = (LogMessageEventHandler) MulticastDelegate.Remove(_LogMessageEventHandler, handler); } public static void AddOnLogSwitchLevel(LogSwitchLevelHandler handler) { lock (locker) _LogSwitchLevelHandler = (LogSwitchLevelHandler) MulticastDelegate.Combine(_LogSwitchLevelHandler, handler); } public static void RemoveOnLogSwitchLevel(LogSwitchLevelHandler handler) { lock (locker) _LogSwitchLevelHandler = (LogSwitchLevelHandler) MulticastDelegate.Remove(_LogSwitchLevelHandler, handler); } internal static void InvokeLogSwitchLevelHandlers (LogSwitch ls, LoggingLevels newLevel) { LogSwitchLevelHandler handler = _LogSwitchLevelHandler; if (handler != null) handler(ls, newLevel); } // Property to Enable/Disable ConsoleDevice. Enabling the console device // adds the console device as a log output, causing any // log messages which make it through filters to be written to the // application console. The console device is enabled by default if the // ??? registry entry or ??? environment variable is set. public static bool IsConsoleEnabled { get { return m_fConsoleDeviceEnabled; } set { m_fConsoleDeviceEnabled = value; } } // AddStream uses the given stream to create and add a new log // device. Any log messages which make it through filters will be written // to the stream. // public static void AddStream(Stream stream) { if (stream==null) throw new ArgumentNullException("stream"); if (m_iStreamArraySize <= m_iNumOfStreamDevices) { // increase array size in chunks of 4 Stream[] newArray = new Stream [m_iStreamArraySize+4]; // copy the old array objects into the new one. if (m_iNumOfStreamDevices > 0) Array.Copy(m_rgStream, newArray, m_iNumOfStreamDevices); m_iStreamArraySize += 4; m_rgStream = newArray; } m_rgStream [m_iNumOfStreamDevices++] = stream; } // Generates a log message. If its switch (or a parent switch) allows the // level for the message, it is "broadcast" to all of the log // devices. // public static void LogMessage(LoggingLevels level, String message) { LogMessage (level, GlobalSwitch, message); } // Generates a log message. If its switch (or a parent switch) allows the // level for the message, it is "broadcast" to all of the log // devices. // [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] public static void LogMessage(LoggingLevels level, LogSwitch logswitch, String message) { if (logswitch == null) throw new ArgumentNullException ("LogSwitch"); if (level < 0) throw new ArgumentOutOfRangeException("level", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); // Is logging for this level for this switch enabled? if (logswitch.CheckLevel (level) == true) { // Send message for logging // first send it to the debugger Debugger.Log ((int) level, logswitch.strName, message); // Send to the console device if (m_fConsoleDeviceEnabled) { Console.Write(message); } // Send it to the streams for (int i=0; i0) Array.Copy(m_rgStream, newArray, m_iNumOfStreamDevices); m_iStreamArraySize += 4; m_rgStream = newArray; } m_rgStream [m_iNumOfStreamDevices++] = stream; } // Generates a log message. If its switch (or a parent switch) allows the // level for the message, it is "broadcast" to all of the log // devices. // public static void LogMessage(LoggingLevels level, String message) { LogMessage (level, GlobalSwitch, message); } // Generates a log message. If its switch (or a parent switch) allows the // level for the message, it is "broadcast" to all of the log // devices. // [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] public static void LogMessage(LoggingLevels level, LogSwitch logswitch, String message) { if (logswitch == null) throw new ArgumentNullException ("LogSwitch"); if (level < 0) throw new ArgumentOutOfRangeException("level", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); // Is logging for this level for this switch enabled? if (logswitch.CheckLevel (level) == true) { // Send message for logging // first send it to the debugger Debugger.Log ((int) level, logswitch.strName, message); // Send to the console device if (m_fConsoleDeviceEnabled) { Console.Write(message); } // Send it to the streams for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlBuilder.cs
- TextElementEnumerator.cs
- TextSerializer.cs
- ParameterBinding.cs
- DPAPIProtectedConfigurationProvider.cs
- StreamGeometry.cs
- TextHidden.cs
- Variant.cs
- Missing.cs
- StreamingContext.cs
- SqlNode.cs
- Debug.cs
- DataServiceHostWrapper.cs
- TextServicesDisplayAttributePropertyRanges.cs
- StylusTip.cs
- ConnectivityStatus.cs
- PackageFilter.cs
- SeparatorAutomationPeer.cs
- CodeSnippetTypeMember.cs
- ServicePoint.cs
- SamlAttributeStatement.cs
- WorkflowDesignerColors.cs
- Int32Collection.cs
- Rotation3D.cs
- WsdlWriter.cs
- XmlJsonReader.cs
- Base64Decoder.cs
- XmlSchemaValidator.cs
- DiscoveryDocumentLinksPattern.cs
- ContextConfiguration.cs
- RelationshipManager.cs
- invalidudtexception.cs
- PageHandlerFactory.cs
- FixedSOMImage.cs
- X509IssuerSerialKeyIdentifierClause.cs
- CompositeDuplexBindingElement.cs
- ServiceCredentialsElement.cs
- ProxyGenerator.cs
- SapiInterop.cs
- PreProcessInputEventArgs.cs
- PublisherIdentityPermission.cs
- LongTypeConverter.cs
- _RegBlobWebProxyDataBuilder.cs
- TypeConverterValueSerializer.cs
- StructuredTypeEmitter.cs
- InternalSafeNativeMethods.cs
- SQLDecimalStorage.cs
- SQLConvert.cs
- SafeNativeMethods.cs
- DragDropHelper.cs
- RunInstallerAttribute.cs
- TextEditorTyping.cs
- AccessDataSourceView.cs
- ModuleConfigurationInfo.cs
- HatchBrush.cs
- CalculatedColumn.cs
- DataSourceXmlSubItemAttribute.cs
- ToolStripOverflowButton.cs
- CachedTypeface.cs
- StylusCaptureWithinProperty.cs
- ApplicationServiceHelper.cs
- XmlSchemaAll.cs
- ConfigurationValues.cs
- XmlSchemaInfo.cs
- XslCompiledTransform.cs
- BulletedListEventArgs.cs
- ConfigurationManagerInternal.cs
- SystemIPGlobalStatistics.cs
- AccessDataSourceView.cs
- SqlRewriteScalarSubqueries.cs
- ReachDocumentSequenceSerializerAsync.cs
- _NegoState.cs
- MsmqHostedTransportConfiguration.cs
- ConfigurationStrings.cs
- XmlSchemaAttribute.cs
- PeekCompletedEventArgs.cs
- SpellerError.cs
- LambdaCompiler.Unary.cs
- COM2ExtendedTypeConverter.cs
- DrawListViewColumnHeaderEventArgs.cs
- PageAsyncTask.cs
- ListViewSelectEventArgs.cs
- ExtensibleClassFactory.cs
- ECDiffieHellman.cs
- SurrogateEncoder.cs
- LambdaCompiler.ControlFlow.cs
- ContentPropertyAttribute.cs
- ScrollContentPresenter.cs
- ToolbarAUtomationPeer.cs
- DragCompletedEventArgs.cs
- CommentGlyph.cs
- LocationChangedEventArgs.cs
- MainMenu.cs
- ConfigUtil.cs
- Semaphore.cs
- TreeNodeStyleCollection.cs
- RelatedImageListAttribute.cs
- XmlSchemaValidationException.cs
- UnconditionalPolicy.cs
- RightsManagementEncryptionTransform.cs