Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / SMDiagnostics / System / ServiceModel / Diagnostics / PiiTraceSource.cs / 1 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DateTimeValueSerializer.cs
- PaperSource.cs
- TabOrder.cs
- XhtmlTextWriter.cs
- ReliableChannelBinder.cs
- StrokeCollectionConverter.cs
- WindowsGraphicsWrapper.cs
- PriorityItem.cs
- BuildProviderCollection.cs
- LicFileLicenseProvider.cs
- ZipFileInfoCollection.cs
- ClassicBorderDecorator.cs
- ZoneIdentityPermission.cs
- ButtonBaseDesigner.cs
- CompilationRelaxations.cs
- CurrentTimeZone.cs
- SchemaImporter.cs
- Stack.cs
- Hyperlink.cs
- XmlSchemaExporter.cs
- Misc.cs
- PropertyGridEditorPart.cs
- ProgressBarBrushConverter.cs
- HttpContext.cs
- DoubleAnimationBase.cs
- Rectangle.cs
- DataBoundControl.cs
- EntityContainerEntitySetDefiningQuery.cs
- InstanceOwnerQueryResult.cs
- MLangCodePageEncoding.cs
- AssemblyNameProxy.cs
- BaseTemplateCodeDomTreeGenerator.cs
- WinEventTracker.cs
- PrintSystemException.cs
- TextRangeSerialization.cs
- EntityDesignerUtils.cs
- RequestDescription.cs
- TraceContext.cs
- ReceiveSecurityHeaderEntry.cs
- DropSource.cs
- ProxyDataContractResolver.cs
- DataControlFieldHeaderCell.cs
- GZipStream.cs
- handlecollector.cs
- grammarelement.cs
- ToolStripPanel.cs
- InstanceValue.cs
- ColorTransform.cs
- _OverlappedAsyncResult.cs
- TypeConverterValueSerializer.cs
- CrossSiteScriptingValidation.cs
- WindowInteropHelper.cs
- RulePatternOps.cs
- DefaultAssemblyResolver.cs
- StringFunctions.cs
- PrintingPermission.cs
- SiteIdentityPermission.cs
- HandledMouseEvent.cs
- StorageBasedPackageProperties.cs
- ColumnMapVisitor.cs
- ImageSource.cs
- FontWeights.cs
- DataGridViewCheckBoxColumn.cs
- IntSumAggregationOperator.cs
- ExecutionTracker.cs
- DataBoundControlActionList.cs
- OutOfProcStateClientManager.cs
- Identity.cs
- AutoGeneratedField.cs
- _FixedSizeReader.cs
- ActiveDocumentEvent.cs
- MimeParameter.cs
- TextEncodedRawTextWriter.cs
- DefaultSection.cs
- PriorityItem.cs
- ListViewEditEventArgs.cs
- DependsOnAttribute.cs
- TextContainerHelper.cs
- Visual3D.cs
- ThicknessKeyFrameCollection.cs
- WebPartDescription.cs
- PieceDirectory.cs
- XmlSchemaElement.cs
- StreamWriter.cs
- GridViewActionList.cs
- DataServiceRequestException.cs
- RequestQueryParser.cs
- SemanticResolver.cs
- WebServiceParameterData.cs
- ISO2022Encoding.cs
- SoapTypeAttribute.cs
- LassoHelper.cs
- RelationshipDetailsCollection.cs
- SatelliteContractVersionAttribute.cs
- URLMembershipCondition.cs
- WebPartConnectionsDisconnectVerb.cs
- SQLSingle.cs
- Ticks.cs
- DataBinder.cs
- Collection.cs