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
- WeakReferenceKey.cs
- EntityDataSourceEntitySetNameItem.cs
- DrawingGroup.cs
- X509CertificateStore.cs
- XMLUtil.cs
- GridViewColumnCollectionChangedEventArgs.cs
- PassportAuthentication.cs
- ComponentConverter.cs
- FontConverter.cs
- NullableDecimalSumAggregationOperator.cs
- Vector3D.cs
- BitmapEffectInput.cs
- PathSegmentCollection.cs
- OdbcPermission.cs
- FormViewInsertEventArgs.cs
- OrderedHashRepartitionEnumerator.cs
- DbDataReader.cs
- IdentityReference.cs
- EditorPartChrome.cs
- StylusEventArgs.cs
- RefreshResponseInfo.cs
- SystemNetworkInterface.cs
- ByteStreamGeometryContext.cs
- SqlUtils.cs
- FlowDocumentPaginator.cs
- HttpApplication.cs
- SqlStatistics.cs
- BooleanSwitch.cs
- QilChoice.cs
- WebPartCancelEventArgs.cs
- KeyEventArgs.cs
- CultureTable.cs
- TextRunProperties.cs
- DataColumn.cs
- BufferedStream.cs
- TrustLevelCollection.cs
- DataObjectSettingDataEventArgs.cs
- MarshalDirectiveException.cs
- AsymmetricKeyExchangeDeformatter.cs
- EventEntry.cs
- Directory.cs
- SafeMarshalContext.cs
- VirtualDirectoryMappingCollection.cs
- BooleanAnimationBase.cs
- BaseDataList.cs
- XmlSchemaObject.cs
- Properties.cs
- DocumentOrderQuery.cs
- _NegotiateClient.cs
- SqlBulkCopyColumnMapping.cs
- CapabilitiesUse.cs
- BezierSegment.cs
- DataContractJsonSerializerOperationFormatter.cs
- WindowsListViewItem.cs
- ListBindableAttribute.cs
- EmptyEnumerator.cs
- DockPattern.cs
- GridPatternIdentifiers.cs
- FixedSOMSemanticBox.cs
- HttpModulesSection.cs
- HttpProfileGroupBase.cs
- Image.cs
- PieceDirectory.cs
- AxisAngleRotation3D.cs
- CaseStatement.cs
- ImageSourceConverter.cs
- ProcessModuleCollection.cs
- RegionData.cs
- CqlWriter.cs
- SerializationSectionGroup.cs
- _NegotiateClient.cs
- filewebresponse.cs
- UriTemplateTrieLocation.cs
- TypeSystem.cs
- InvalidDataException.cs
- MessageAction.cs
- KeyConverter.cs
- UriTemplateVariablePathSegment.cs
- SqlBooleanizer.cs
- SequentialActivityDesigner.cs
- EmptyTextWriter.cs
- OleCmdHelper.cs
- VisualBrush.cs
- StreamWithDictionary.cs
- SaveFileDialogDesigner.cs
- RelationshipDetailsRow.cs
- Queue.cs
- _NativeSSPI.cs
- TargetPerspective.cs
- RectangleGeometry.cs
- UiaCoreProviderApi.cs
- HyperLinkDesigner.cs
- SymmetricSecurityBindingElement.cs
- ThreadSafeList.cs
- TransactionContext.cs
- CollectionBase.cs
- SID.cs
- SnapLine.cs
- MethodCallExpression.cs
- StringDictionaryEditor.cs