Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CompMod / System / Diagnostics / TraceEventCache.cs / 1305376 / TraceEventCache.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Threading; using System.Security.Permissions; using System.Text; using System.Collections; using System.Globalization; using System.Runtime.Versioning; namespace System.Diagnostics { public class TraceEventCache { private static int processId; private static string processName; private long timeStamp = -1; private DateTime dateTime = DateTime.MinValue; private string stackTrace = null; internal Guid ActivityId { get { return Trace.CorrelationManager.ActivityId; } } public string Callstack { get { if (stackTrace == null) stackTrace = Environment.StackTrace; else new EnvironmentPermission(PermissionState.Unrestricted).Demand(); return stackTrace; } } public Stack LogicalOperationStack { get { return Trace.CorrelationManager.LogicalOperationStack; } } public DateTime DateTime { get { if (dateTime == DateTime.MinValue) dateTime = DateTime.UtcNow; return dateTime; } } public int ProcessId { [ResourceExposure(ResourceScope.Process)] // Returns the current process's pid [ResourceConsumption(ResourceScope.Process)] get { return GetProcessId(); } } public string ThreadId { get { return GetThreadId().ToString(CultureInfo.InvariantCulture); } } public long Timestamp { get { if (timeStamp == -1) timeStamp = Stopwatch.GetTimestamp(); return timeStamp ; } } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] private static void InitProcessInfo() { // Demand unmanaged code permission new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); if (processName == null) { Process p = Process.GetCurrentProcess(); try { processId = p.Id; processName = p.ProcessName; } finally { p.Dispose(); } } } [ResourceExposure(ResourceScope.Process)] internal static int GetProcessId() { InitProcessInfo(); return processId; } internal static string GetProcessName() { InitProcessInfo(); return processName; } internal static int GetThreadId() { return Thread.CurrentThread.ManagedThreadId; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Threading; using System.Security.Permissions; using System.Text; using System.Collections; using System.Globalization; using System.Runtime.Versioning; namespace System.Diagnostics { public class TraceEventCache { private static int processId; private static string processName; private long timeStamp = -1; private DateTime dateTime = DateTime.MinValue; private string stackTrace = null; internal Guid ActivityId { get { return Trace.CorrelationManager.ActivityId; } } public string Callstack { get { if (stackTrace == null) stackTrace = Environment.StackTrace; else new EnvironmentPermission(PermissionState.Unrestricted).Demand(); return stackTrace; } } public Stack LogicalOperationStack { get { return Trace.CorrelationManager.LogicalOperationStack; } } public DateTime DateTime { get { if (dateTime == DateTime.MinValue) dateTime = DateTime.UtcNow; return dateTime; } } public int ProcessId { [ResourceExposure(ResourceScope.Process)] // Returns the current process's pid [ResourceConsumption(ResourceScope.Process)] get { return GetProcessId(); } } public string ThreadId { get { return GetThreadId().ToString(CultureInfo.InvariantCulture); } } public long Timestamp { get { if (timeStamp == -1) timeStamp = Stopwatch.GetTimestamp(); return timeStamp ; } } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] private static void InitProcessInfo() { // Demand unmanaged code permission new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); if (processName == null) { Process p = Process.GetCurrentProcess(); try { processId = p.Id; processName = p.ProcessName; } finally { p.Dispose(); } } } [ResourceExposure(ResourceScope.Process)] internal static int GetProcessId() { InitProcessInfo(); return processId; } internal static string GetProcessName() { InitProcessInfo(); return processName; } internal static int GetThreadId() { return Thread.CurrentThread.ManagedThreadId; } } } // 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
- DataSourceBooleanViewSchemaConverter.cs
- CreateUserWizardAutoFormat.cs
- ArgumentNullException.cs
- Padding.cs
- IgnoreDeviceFilterElement.cs
- ManagementOperationWatcher.cs
- BitmapImage.cs
- NestedContainer.cs
- HttpPostProtocolReflector.cs
- DocComment.cs
- CompoundFileReference.cs
- SqlBooleanMismatchVisitor.cs
- CodeArrayIndexerExpression.cs
- OdbcTransaction.cs
- SystemIPGlobalProperties.cs
- PropVariant.cs
- Screen.cs
- ConstraintEnumerator.cs
- OTFRasterizer.cs
- ColorIndependentAnimationStorage.cs
- NotifyParentPropertyAttribute.cs
- HttpWebRequest.cs
- DataGridColumnEventArgs.cs
- ToolTipService.cs
- DbParameterHelper.cs
- XmlSchemaObjectCollection.cs
- ConstructorBuilder.cs
- Nodes.cs
- DataGridSortCommandEventArgs.cs
- StateValidator.cs
- ContextMenuAutomationPeer.cs
- AuthorizationContext.cs
- SelectionRangeConverter.cs
- ListViewTableCell.cs
- StringCollection.cs
- ButtonPopupAdapter.cs
- PropertyGridView.cs
- SuppressMessageAttribute.cs
- StateMachineSubscription.cs
- SourceFileBuildProvider.cs
- EncryptedPackageFilter.cs
- DataGridViewRowPrePaintEventArgs.cs
- TextBox.cs
- Errors.cs
- FloatSumAggregationOperator.cs
- GZipUtils.cs
- PropertyFilterAttribute.cs
- BindingExpressionUncommonField.cs
- CompiledRegexRunner.cs
- WorkflowApplicationEventArgs.cs
- SqlServices.cs
- FixedStringLookup.cs
- ToggleButton.cs
- ControllableStoryboardAction.cs
- TextContainer.cs
- SafeReversePInvokeHandle.cs
- ExpressionsCollectionEditor.cs
- MapPathBasedVirtualPathProvider.cs
- ReadOnlyTernaryTree.cs
- FreezableCollection.cs
- MenuItemStyleCollection.cs
- SystemKeyConverter.cs
- SplineKeyFrames.cs
- RectangleF.cs
- PeerPresenceInfo.cs
- BindingManagerDataErrorEventArgs.cs
- ValueTable.cs
- TextModifier.cs
- UniqueIdentifierService.cs
- WebPartConnectionsCancelEventArgs.cs
- BatchParser.cs
- BamlVersionHeader.cs
- ScrollableControl.cs
- ContentElement.cs
- Root.cs
- ContainerFilterService.cs
- FormCollection.cs
- RemotingConfiguration.cs
- RequestCache.cs
- FullTrustAssembly.cs
- RouteParser.cs
- unsafenativemethodstextservices.cs
- XslAst.cs
- PixelFormats.cs
- ListViewItem.cs
- PointLightBase.cs
- Helper.cs
- PointLight.cs
- COM2AboutBoxPropertyDescriptor.cs
- MetaType.cs
- XmlnsCache.cs
- SymmetricKeyWrap.cs
- TypeDescriptionProviderAttribute.cs
- MetadataPropertyAttribute.cs
- ZoneMembershipCondition.cs
- MarkupObject.cs
- DependencySource.cs
- DependencyPropertyHelper.cs
- Asn1Utilities.cs
- SQLInt16.cs