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
- Root.cs
- CacheAxisQuery.cs
- TrackingServices.cs
- StrokeNodeEnumerator.cs
- DecryptedHeader.cs
- BinaryNode.cs
- ImageIndexConverter.cs
- DataBinder.cs
- RegexTypeEditor.cs
- ItemsPresenter.cs
- RichTextBoxAutomationPeer.cs
- Set.cs
- ListView.cs
- Size3D.cs
- SynchronizationContext.cs
- SafeLibraryHandle.cs
- StrongNameUtility.cs
- TableStyle.cs
- VectorCollectionConverter.cs
- CustomAttributeBuilder.cs
- ExpressionNode.cs
- XmlReader.cs
- RepeatBehaviorConverter.cs
- DefinitionUpdate.cs
- DependencyObjectCodeDomSerializer.cs
- ComNativeDescriptor.cs
- PersonalizablePropertyEntry.cs
- FixedSOMGroup.cs
- CompilerTypeWithParams.cs
- ReaderWriterLock.cs
- XmlSchemas.cs
- Hash.cs
- WasHttpModulesInstallComponent.cs
- BufferedGraphicsManager.cs
- EtwTrace.cs
- Inflater.cs
- DBSchemaTable.cs
- FormViewUpdateEventArgs.cs
- ListenUriMode.cs
- TreePrinter.cs
- BamlTreeUpdater.cs
- ClientProtocol.cs
- TextTreeNode.cs
- TextTreeTextBlock.cs
- HtmlControl.cs
- UserNameServiceElement.cs
- TemplateBindingExtensionConverter.cs
- DomNameTable.cs
- VectorAnimation.cs
- ConstNode.cs
- XmlSchemaObject.cs
- GridViewEditEventArgs.cs
- NativeRightsManagementAPIsStructures.cs
- UrlPath.cs
- NameValueSectionHandler.cs
- UInt32Converter.cs
- IsolationInterop.cs
- MobileComponentEditorPage.cs
- ChangePasswordAutoFormat.cs
- DataGridViewTopLeftHeaderCell.cs
- TreeNodeMouseHoverEvent.cs
- PerformanceCounterLib.cs
- NameValueFileSectionHandler.cs
- TransformValueSerializer.cs
- RepeaterItemEventArgs.cs
- DataGridViewDataConnection.cs
- TypeBrowserDialog.cs
- SafeLocalMemHandle.cs
- ObjectView.cs
- CallSite.cs
- ConstructorNeedsTagAttribute.cs
- PointCollection.cs
- OwnerDrawPropertyBag.cs
- BroadcastEventHelper.cs
- BaseCAMarshaler.cs
- PointAnimationUsingKeyFrames.cs
- BamlReader.cs
- DataGridTextBoxColumn.cs
- CompositeDataBoundControl.cs
- TraceXPathNavigator.cs
- CategoryList.cs
- ValueOfAction.cs
- Cursors.cs
- XsltSettings.cs
- DotExpr.cs
- CompositeDataBoundControl.cs
- HelpProvider.cs
- ExpressionBuilderContext.cs
- CharEntityEncoderFallback.cs
- WindowsContainer.cs
- RadioButtonFlatAdapter.cs
- UIElementParagraph.cs
- ViewPort3D.cs
- smtppermission.cs
- TextServicesProperty.cs
- FileSystemEventArgs.cs
- WebPartManager.cs
- UserControl.cs
- RotateTransform.cs
- OptimizedTemplateContent.cs