Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / SMDiagnostics / System / ServiceModel / Diagnostics / PiiTraceSource.cs / 1305376 / PiiTraceSource.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using System.Configuration; // using System.ServiceModel.Channels; using System.Diagnostics; using System.ServiceModel.Configuration; class PiiTraceSource : TraceSource { string eventSourceName = String.Empty; internal const string LogPii = "logKnownPii"; bool shouldLogPii = false; bool initialized = false; object localSyncObject = new object(); internal PiiTraceSource(string name, string eventSourceName) : base(name) { #pragma warning disable 618 AssertUtility.DebugAssert(!String.IsNullOrEmpty(eventSourceName), "Event log source name must be valid"); #pragma warning restore 618 this.eventSourceName = eventSourceName; } internal PiiTraceSource(string name, string eventSourceName, SourceLevels levels) : base(name, levels) { #pragma warning disable 618 AssertUtility.DebugAssert(!String.IsNullOrEmpty(eventSourceName), "Event log source name must be valid"); #pragma warning restore 618 this.eventSourceName = eventSourceName; } void Initialize() { if (!this.initialized) { lock (localSyncObject) { if (!this.initialized) { string attributeValue = this.Attributes[PiiTraceSource.LogPii]; bool shouldLogPii = false; if (!string.IsNullOrEmpty(attributeValue)) { if (!bool.TryParse(attributeValue, out shouldLogPii)) { shouldLogPii = false; } } if (shouldLogPii) { #pragma warning disable 618 EventLogger logger = new EventLogger(this.eventSourceName, null); #pragma warning restore 618 if (MachineSettingsSection.EnableLoggingKnownPii) { logger.LogEvent(TraceEventType.Information, EventLogCategory.MessageLogging, EventLogEventId.PiiLoggingOn, false); this.shouldLogPii = true; } else { logger.LogEvent(TraceEventType.Error, EventLogCategory.MessageLogging, EventLogEventId.PiiLoggingNotAllowed, false); } } this.initialized = true; } } } } protected override string[] GetSupportedAttributes() { return new string[] { PiiTraceSource.LogPii }; } internal bool ShouldLogPii { get { // ShouldLogPii is called very frequently, don't call Initialize unless we have to. if (!this.initialized) { Initialize(); } return this.shouldLogPii; } set { // If you call this, you know what you're doing this.initialized = true; this.shouldLogPii = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Diagnostics { using System.Configuration; // using System.ServiceModel.Channels; using System.Diagnostics; using System.ServiceModel.Configuration; class PiiTraceSource : TraceSource { string eventSourceName = String.Empty; internal const string LogPii = "logKnownPii"; bool shouldLogPii = false; bool initialized = false; object localSyncObject = new object(); internal PiiTraceSource(string name, string eventSourceName) : base(name) { #pragma warning disable 618 AssertUtility.DebugAssert(!String.IsNullOrEmpty(eventSourceName), "Event log source name must be valid"); #pragma warning restore 618 this.eventSourceName = eventSourceName; } internal PiiTraceSource(string name, string eventSourceName, SourceLevels levels) : base(name, levels) { #pragma warning disable 618 AssertUtility.DebugAssert(!String.IsNullOrEmpty(eventSourceName), "Event log source name must be valid"); #pragma warning restore 618 this.eventSourceName = eventSourceName; } void Initialize() { if (!this.initialized) { lock (localSyncObject) { if (!this.initialized) { string attributeValue = this.Attributes[PiiTraceSource.LogPii]; bool shouldLogPii = false; if (!string.IsNullOrEmpty(attributeValue)) { if (!bool.TryParse(attributeValue, out shouldLogPii)) { shouldLogPii = false; } } if (shouldLogPii) { #pragma warning disable 618 EventLogger logger = new EventLogger(this.eventSourceName, null); #pragma warning restore 618 if (MachineSettingsSection.EnableLoggingKnownPii) { logger.LogEvent(TraceEventType.Information, EventLogCategory.MessageLogging, EventLogEventId.PiiLoggingOn, false); this.shouldLogPii = true; } else { logger.LogEvent(TraceEventType.Error, EventLogCategory.MessageLogging, EventLogEventId.PiiLoggingNotAllowed, false); } } this.initialized = true; } } } } protected override string[] GetSupportedAttributes() { return new string[] { PiiTraceSource.LogPii }; } internal bool ShouldLogPii { get { // ShouldLogPii is called very frequently, don't call Initialize unless we have to. if (!this.initialized) { Initialize(); } return this.shouldLogPii; } set { // If you call this, you know what you're doing this.initialized = true; this.shouldLogPii = value; } } } } // 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
- storepermission.cs
- ClientConfigurationSystem.cs
- DataGridViewRowsRemovedEventArgs.cs
- UnsafeNativeMethods.cs
- MenuItemCollection.cs
- SpecialNameAttribute.cs
- ContainerUtilities.cs
- hresults.cs
- SqlCaseSimplifier.cs
- ImportCatalogPart.cs
- FontSizeConverter.cs
- SQLInt16.cs
- AutomationFocusChangedEventArgs.cs
- Object.cs
- OuterGlowBitmapEffect.cs
- KeyPressEvent.cs
- GridPattern.cs
- Peer.cs
- WebPartsPersonalization.cs
- ScriptControl.cs
- ToolboxItemFilterAttribute.cs
- ConnectivityStatus.cs
- MetadataUtilsSmi.cs
- EventData.cs
- CodeTypeReferenceCollection.cs
- MimeParameterWriter.cs
- PropertyDescriptorComparer.cs
- WebPartEditVerb.cs
- VirtualDirectoryMapping.cs
- SizeAnimationUsingKeyFrames.cs
- BaseDataBoundControl.cs
- PeerTransportListenAddressConverter.cs
- counter.cs
- PageMediaType.cs
- DateTimeFormatInfo.cs
- FileVersion.cs
- ToolboxComponentsCreatedEventArgs.cs
- SelectedDatesCollection.cs
- RecipientInfo.cs
- Message.cs
- WindowsStartMenu.cs
- WebPartConnectionsConfigureVerb.cs
- CryptoProvider.cs
- RemotingSurrogateSelector.cs
- RSAOAEPKeyExchangeFormatter.cs
- Error.cs
- RoleService.cs
- FontDifferentiator.cs
- Emitter.cs
- StdRegProviderWrapper.cs
- SqlVersion.cs
- AssemblyUtil.cs
- MorphHelper.cs
- KnownColorTable.cs
- RadialGradientBrush.cs
- controlskin.cs
- WebPartTransformerCollection.cs
- ProviderConnectionPoint.cs
- WebPartEventArgs.cs
- BindableTemplateBuilder.cs
- TableAdapterManagerMethodGenerator.cs
- ReflectionServiceProvider.cs
- ToolStripContentPanel.cs
- RemoteWebConfigurationHost.cs
- DependencyObjectPropertyDescriptor.cs
- BitmapEffectDrawingContextState.cs
- Tokenizer.cs
- NamespaceEmitter.cs
- DetailsViewDeleteEventArgs.cs
- EventLogRecord.cs
- XmlIgnoreAttribute.cs
- X509Chain.cs
- XmlSchemaSimpleTypeRestriction.cs
- PeerResolverBindingElement.cs
- ResourceWriter.cs
- PageHandlerFactory.cs
- FormViewPageEventArgs.cs
- SuppressMessageAttribute.cs
- MsmqPoisonMessageException.cs
- SHA1CryptoServiceProvider.cs
- XmlComment.cs
- Transform3DCollection.cs
- TypedReference.cs
- TextRangeAdaptor.cs
- MailHeaderInfo.cs
- ListItemConverter.cs
- Action.cs
- QueryCacheManager.cs
- ApplicationServiceHelper.cs
- FormDocumentDesigner.cs
- DbTransaction.cs
- GeneralTransform3DTo2D.cs
- FixUpCollection.cs
- Utils.cs
- StatusBarDrawItemEvent.cs
- CodeNamespaceImport.cs
- OutputCacheProfile.cs
- SkinBuilder.cs
- WebPartEditorCancelVerb.cs
- MimeTypePropertyAttribute.cs