Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SmiEventSink_Default.cs
- AstTree.cs
- SchemaSetCompiler.cs
- WebPartHelpVerb.cs
- DetailsViewRowCollection.cs
- KeyFrames.cs
- InvokeHandlers.cs
- MatrixTransform.cs
- DefaultTextStoreTextComposition.cs
- AutoGeneratedFieldProperties.cs
- HandlerFactoryCache.cs
- Serializer.cs
- HasCopySemanticsAttribute.cs
- PairComparer.cs
- NameGenerator.cs
- _AutoWebProxyScriptEngine.cs
- RequestNavigateEventArgs.cs
- MessageDecoder.cs
- Control.cs
- Color.cs
- EntityKeyElement.cs
- FixedSOMPageConstructor.cs
- SplineQuaternionKeyFrame.cs
- BooleanToVisibilityConverter.cs
- TextElementEditingBehaviorAttribute.cs
- SeparatorAutomationPeer.cs
- ComAdminInterfaces.cs
- TextCompositionManager.cs
- CodeBlockBuilder.cs
- CaseInsensitiveComparer.cs
- ComAwareEventInfo.cs
- CompositionTarget.cs
- DataControlImageButton.cs
- SafeNativeMethodsMilCoreApi.cs
- Win32SafeHandles.cs
- SubtreeProcessor.cs
- TreeViewImageIndexConverter.cs
- ColumnResizeAdorner.cs
- DocumentSchemaValidator.cs
- TrackingDataItem.cs
- QuadTree.cs
- EntityTypeBase.cs
- RequestCacheManager.cs
- CodeGeneratorOptions.cs
- DelegateSerializationHolder.cs
- SmtpNetworkElement.cs
- basemetadatamappingvisitor.cs
- ChangeDirector.cs
- ColorConverter.cs
- XmlSiteMapProvider.cs
- XMLSchema.cs
- BlobPersonalizationState.cs
- ResourceType.cs
- Utils.cs
- LinearGradientBrush.cs
- FileSystemEventArgs.cs
- DbConnectionClosed.cs
- ResourceSet.cs
- XpsSerializerFactory.cs
- StateManagedCollection.cs
- MetadataSource.cs
- PointLight.cs
- BitmapSource.cs
- CursorConverter.cs
- Button.cs
- IriParsingElement.cs
- ControlBuilderAttribute.cs
- SessionSymmetricTransportSecurityProtocolFactory.cs
- NotificationContext.cs
- RequestNavigateEventArgs.cs
- MD5.cs
- Logging.cs
- ObjectDataSourceSelectingEventArgs.cs
- EventProviderWriter.cs
- LoginName.cs
- TreeNodeBindingCollection.cs
- MeasureData.cs
- PreloadHost.cs
- AtomServiceDocumentSerializer.cs
- RowBinding.cs
- StaticDataManager.cs
- DataGridLinkButton.cs
- DurableInstanceContextProvider.cs
- ControlAdapter.cs
- Int32RectConverter.cs
- AutomationTextAttribute.cs
- SQLDateTimeStorage.cs
- ExtensionSimplifierMarkupObject.cs
- ListViewItem.cs
- WebPartDescriptionCollection.cs
- ErrorInfoXmlDocument.cs
- xmlglyphRunInfo.cs
- HTMLTextWriter.cs
- EntityDataSourceContainerNameItem.cs
- XmlSchemaObjectCollection.cs
- MultipleViewPattern.cs
- SpecialFolderEnumConverter.cs
- StateBag.cs
- ActivatableWorkflowsQueryResult.cs
- X500Name.cs