You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,141 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class ActivityIdHeader : DictionaryHeader
|
||||
{
|
||||
Guid guid;
|
||||
Guid headerId;
|
||||
|
||||
internal ActivityIdHeader(Guid activityId)
|
||||
: base()
|
||||
{
|
||||
this.guid = activityId;
|
||||
this.headerId = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public override XmlDictionaryString DictionaryName
|
||||
{
|
||||
get { return XD.ActivityIdFlowDictionary.ActivityId; }
|
||||
}
|
||||
|
||||
public override XmlDictionaryString DictionaryNamespace
|
||||
{
|
||||
get { return XD.ActivityIdFlowDictionary.ActivityIdNamespace; }
|
||||
}
|
||||
|
||||
internal static Guid ExtractActivityId(Message message)
|
||||
{
|
||||
Guid guid = Guid.Empty;
|
||||
try
|
||||
{
|
||||
if (message != null && message.State != MessageState.Closed && message.Headers != null)
|
||||
{
|
||||
int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);
|
||||
|
||||
// Check the state again, in case the message was closed after we found the header
|
||||
if (index >= 0)
|
||||
{
|
||||
using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index))
|
||||
{
|
||||
guid = reader.ReadElementContentAsGuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (DiagnosticUtility.ShouldTraceError)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.FailedToReadAnActivityIdHeader,
|
||||
SR.GetString(SR.TraceCodeFailedToReadAnActivityIdHeader), null, e);
|
||||
}
|
||||
}
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
internal static bool ExtractActivityAndCorrelationId(Message message, out Guid activityId, out Guid correlationId)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
|
||||
}
|
||||
activityId = Guid.Empty;
|
||||
correlationId = Guid.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
if (message.State != MessageState.Closed && message.Headers != null)
|
||||
{
|
||||
int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);
|
||||
|
||||
// Check the state again, in case the message was closed after we found the header
|
||||
if (index >= 0)
|
||||
{
|
||||
using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index))
|
||||
{
|
||||
correlationId = Fx.CreateGuid(reader.GetAttribute("CorrelationId", null));
|
||||
activityId = reader.ReadElementContentAsGuid();
|
||||
return activityId != Guid.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (DiagnosticUtility.ShouldTraceError)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.FailedToReadAnActivityIdHeader,
|
||||
SR.GetString(SR.TraceCodeFailedToReadAnActivityIdHeader), null, e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void AddTo(Message message)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
|
||||
}
|
||||
if (message.State != MessageState.Closed && message.Headers.MessageVersion.Envelope != EnvelopeVersion.None)
|
||||
{
|
||||
int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);
|
||||
if (index < 0)
|
||||
{
|
||||
message.Headers.Add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
|
||||
}
|
||||
writer.WriteAttributeString("CorrelationId", this.headerId.ToString());
|
||||
writer.WriteValue(this.guid);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
enum ActivityType
|
||||
{
|
||||
Unknown,
|
||||
Close,
|
||||
Construct,
|
||||
ExecuteUserCode,
|
||||
ListenAt,
|
||||
Open,
|
||||
OpenClient,
|
||||
ProcessMessage,
|
||||
ProcessAction,
|
||||
ReceiveBytes,
|
||||
SecuritySetup,
|
||||
TransferToComPlus,
|
||||
WmiGetObject,
|
||||
WmiPutInstance,
|
||||
NumItems, // leave this item at the end of the list.
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Runtime;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class AddressingProperty
|
||||
{
|
||||
string action;
|
||||
Uri to;
|
||||
EndpointAddress replyTo;
|
||||
System.Xml.UniqueId messageId;
|
||||
|
||||
public AddressingProperty(MessageHeaders headers)
|
||||
{
|
||||
Fx.Assert(null != headers, "");
|
||||
|
||||
this.action = headers.Action;
|
||||
this.to = headers.To;
|
||||
this.replyTo = headers.ReplyTo;
|
||||
this.messageId = headers.MessageId;
|
||||
}
|
||||
|
||||
public string Action
|
||||
{
|
||||
get { return this.action; }
|
||||
}
|
||||
|
||||
public UniqueId MessageId
|
||||
{
|
||||
get { return this.messageId; }
|
||||
}
|
||||
|
||||
public static string Name
|
||||
{
|
||||
get { return MessageLogTraceRecord.AddressingElementName; }
|
||||
}
|
||||
|
||||
public EndpointAddress ReplyTo
|
||||
{
|
||||
get { return this.replyTo; }
|
||||
}
|
||||
|
||||
public Uri To
|
||||
{
|
||||
get { return this.to; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class ChannelTraceRecord : TraceRecord
|
||||
{
|
||||
string channelType;
|
||||
|
||||
internal ChannelTraceRecord(IChannel channel)
|
||||
{
|
||||
this.channelType = channel == null ? null : channel.ToString();
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("Channel"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
if (this.channelType != null)
|
||||
{
|
||||
xml.WriteElementString("ChannelType", this.channelType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.Xml;
|
||||
|
||||
class CollectionTraceRecord : TraceRecord
|
||||
{
|
||||
IEnumerable entries;
|
||||
string collectionName;
|
||||
string elementName;
|
||||
|
||||
public CollectionTraceRecord(string collectionName, string elementName, IEnumerable entries)
|
||||
{
|
||||
this.collectionName = String.IsNullOrEmpty(collectionName) ? "Elements" : collectionName;
|
||||
this.elementName = String.IsNullOrEmpty(elementName) ? "Element" : elementName;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("Collection"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
if (this.entries != null)
|
||||
{
|
||||
xml.WriteStartElement(this.collectionName);
|
||||
foreach (object element in this.entries)
|
||||
{
|
||||
xml.WriteElementString(this.elementName, element == null ? "null" : element.ToString());
|
||||
}
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,140 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel;
|
||||
|
||||
internal class DefaultPerformanceCounters : PerformanceCountersBase
|
||||
{
|
||||
string instanceName;
|
||||
|
||||
enum PerfCounters : int
|
||||
{
|
||||
Instances = 0,
|
||||
TotalCounters = Instances + 1
|
||||
}
|
||||
|
||||
string[] perfCounterNames =
|
||||
{
|
||||
PerformanceCounterStrings.SERVICEMODELSERVICE.SInstances,
|
||||
};
|
||||
|
||||
const int maxCounterLength = 64;
|
||||
const int hashLength = 2;
|
||||
[Flags]
|
||||
enum truncOptions : uint
|
||||
{
|
||||
NoBits = 0,
|
||||
service32 = 0x01,
|
||||
uri31 = 0x04
|
||||
}
|
||||
|
||||
internal PerformanceCounter[] Counters { get; set; }
|
||||
|
||||
internal override string InstanceName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.instanceName;
|
||||
}
|
||||
}
|
||||
|
||||
internal override string[] CounterNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.perfCounterNames;
|
||||
}
|
||||
}
|
||||
|
||||
internal override int PerfCounterStart
|
||||
{
|
||||
get { return (int)PerfCounters.Instances; }
|
||||
}
|
||||
|
||||
internal override int PerfCounterEnd
|
||||
{
|
||||
get { return (int)PerfCounters.TotalCounters; }
|
||||
}
|
||||
|
||||
static internal string CreateFriendlyInstanceName(ServiceHostBase serviceHost)
|
||||
{
|
||||
// It is a shared instance across all services which have the default counter enabled
|
||||
return "_WCF_Admin";
|
||||
}
|
||||
|
||||
internal DefaultPerformanceCounters(ServiceHostBase serviceHost)
|
||||
{
|
||||
this.instanceName = DefaultPerformanceCounters.CreateFriendlyInstanceName(serviceHost);
|
||||
this.Counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
|
||||
for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
PerformanceCounter counter = PerformanceCounters.GetDefaultPerformanceCounter(this.perfCounterNames[i], this.instanceName);
|
||||
if (counter != null)
|
||||
{
|
||||
this.Counters[i] = counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (DiagnosticUtility.ShouldTraceError)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCountersFailedForService,
|
||||
SR.GetString(SR.TraceCodePerformanceCountersFailedForService), null, e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal override bool Initialized
|
||||
{
|
||||
get { return this.Counters != null; }
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (PerformanceCounters.PerformanceCountersEnabled)
|
||||
{
|
||||
if (null != this.Counters)
|
||||
{
|
||||
for (int ctr = this.PerfCounterStart; ctr < this.PerfCounterEnd; ++ctr)
|
||||
{
|
||||
PerformanceCounter counter = this.Counters[ctr];
|
||||
if (counter != null)
|
||||
{
|
||||
PerformanceCounters.ReleasePerformanceCounter(ref counter);
|
||||
}
|
||||
this.Counters[ctr] = null;
|
||||
}
|
||||
this.Counters = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,166 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.Runtime;
|
||||
|
||||
sealed class EndpointPerformanceCounters : EndpointPerformanceCountersBase
|
||||
{
|
||||
internal PerformanceCounter[] Counters { get; set; }
|
||||
|
||||
internal EndpointPerformanceCounters(string service, string contract, string uri)
|
||||
: base(service, contract, uri)
|
||||
{
|
||||
|
||||
this.Counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
|
||||
for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
|
||||
{
|
||||
PerformanceCounter counter = PerformanceCounters.GetEndpointPerformanceCounter(perfCounterNames[i], this.instanceName);
|
||||
if (counter != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
counter.RawValue = 0;
|
||||
this.Counters[i] = counter;
|
||||
}
|
||||
#pragma warning suppress 56500 // covered by FxCOP
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Fx.IsFatal(e))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
if (DiagnosticUtility.ShouldTraceError)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCounterFailedToLoad,
|
||||
SR.GetString(SR.TraceCodePerformanceCounterFailedToLoad), null, e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Increment(int counter)
|
||||
{
|
||||
this.Increment(this.Counters, counter);
|
||||
}
|
||||
|
||||
void IncrementBy(int counter, long time)
|
||||
{
|
||||
this.IncrementBy(this.Counters, counter, time);
|
||||
}
|
||||
|
||||
void Decrement(int counter)
|
||||
{
|
||||
this.Decrement(this.Counters, counter);
|
||||
}
|
||||
|
||||
internal override void MethodCalled()
|
||||
{
|
||||
Increment((int)PerfCounters.Calls);
|
||||
Increment((int)PerfCounters.CallsPerSecond);
|
||||
Increment((int)PerfCounters.CallsOutstanding);
|
||||
}
|
||||
|
||||
internal override void MethodReturnedSuccess()
|
||||
{
|
||||
Decrement((int)PerfCounters.CallsOutstanding);
|
||||
}
|
||||
|
||||
|
||||
internal override void MethodReturnedError()
|
||||
{
|
||||
Increment((int)PerfCounters.CallsFailed);
|
||||
Increment((int)PerfCounters.CallsFailedPerSecond);
|
||||
Decrement((int)PerfCounters.CallsOutstanding);
|
||||
}
|
||||
|
||||
internal override void MethodReturnedFault()
|
||||
{
|
||||
Increment((int)PerfCounters.CallsFaulted);
|
||||
Increment((int)PerfCounters.CallsFaultedPerSecond);
|
||||
Decrement((int)PerfCounters.CallsOutstanding);
|
||||
}
|
||||
|
||||
|
||||
internal override void SaveCallDuration(long time)
|
||||
{
|
||||
IncrementBy((int)PerfCounters.CallDuration, time);
|
||||
Increment((int)PerfCounters.CallDurationBase);
|
||||
}
|
||||
|
||||
internal override void AuthenticationFailed()
|
||||
{
|
||||
Increment((int)PerfCounters.SecurityValidationAuthenticationFailures);
|
||||
Increment((int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond);
|
||||
}
|
||||
|
||||
internal override void AuthorizationFailed()
|
||||
{
|
||||
Increment((int)PerfCounters.CallsNotAuthorized);
|
||||
Increment((int)PerfCounters.CallsNotAuthorizedPerSecond);
|
||||
}
|
||||
|
||||
internal override void SessionFaulted()
|
||||
{
|
||||
Increment((int)PerfCounters.RMSessionsFaulted);
|
||||
Increment((int)PerfCounters.RMSessionsFaultedPerSecond);
|
||||
}
|
||||
|
||||
internal override void MessageDropped()
|
||||
{
|
||||
Increment((int)PerfCounters.RMMessagesDropped);
|
||||
Increment((int)PerfCounters.RMMessagesDroppedPerSecond);
|
||||
}
|
||||
|
||||
internal override void TxFlowed()
|
||||
{
|
||||
Increment((int)PerfCounters.TxFlowed);
|
||||
Increment((int)PerfCounters.TxFlowedPerSecond);
|
||||
}
|
||||
|
||||
internal override bool Initialized
|
||||
{
|
||||
get { return this.Counters != null; }
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (PerformanceCounters.PerformanceCountersEnabled)
|
||||
{
|
||||
if (null != this.Counters)
|
||||
{
|
||||
for (int ctr = this.PerfCounterStart; ctr < this.PerfCounterEnd; ++ctr)
|
||||
{
|
||||
PerformanceCounter counter = this.Counters[ctr];
|
||||
if (counter != null)
|
||||
{
|
||||
PerformanceCounters.ReleasePerformanceCounter(ref counter);
|
||||
}
|
||||
this.Counters[ctr] = null;
|
||||
}
|
||||
this.Counters = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,223 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Administration;
|
||||
using System.Diagnostics.PerformanceData;
|
||||
|
||||
abstract class EndpointPerformanceCountersBase : PerformanceCountersBase
|
||||
{
|
||||
protected string instanceName;
|
||||
|
||||
protected enum PerfCounters : int
|
||||
{
|
||||
Calls = 0,
|
||||
CallsPerSecond,
|
||||
CallsOutstanding,
|
||||
CallsFailed,
|
||||
CallsFailedPerSecond,
|
||||
CallsFaulted,
|
||||
CallsFaultedPerSecond,
|
||||
CallDuration,
|
||||
CallDurationBase,
|
||||
SecurityValidationAuthenticationFailures,
|
||||
SecurityValidationAuthenticationFailuresPerSecond,
|
||||
CallsNotAuthorized,
|
||||
CallsNotAuthorizedPerSecond,
|
||||
RMSessionsFaulted,
|
||||
RMSessionsFaultedPerSecond,
|
||||
RMMessagesDropped,
|
||||
RMMessagesDroppedPerSecond,
|
||||
TxFlowed,
|
||||
TxFlowedPerSecond,
|
||||
TotalCounters = TxFlowedPerSecond + 1
|
||||
}
|
||||
|
||||
protected static readonly string[] perfCounterNames =
|
||||
{
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECalls,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsOutstanding,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFailed,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFailedPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFaulted,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallsFaultedPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallDuration,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ECallDurationBase,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityValidationAuthenticationFailures,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityValidationAuthenticationFailuresPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityCallsNotAuthorized,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ESecurityCallsNotAuthorizedPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMSessionsFaulted,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMSessionsFaultedPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMMessagesDropped,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ERMMessagesDroppedPerSecond,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ETxFlowed,
|
||||
PerformanceCounterStrings.SERVICEMODELENDPOINT.ETxFlowedPerSecond,
|
||||
};
|
||||
|
||||
const int maxCounterLength = 64;
|
||||
const int hashLength = 2;
|
||||
[Flags]
|
||||
enum truncOptions : uint
|
||||
{
|
||||
NoBits = 0,
|
||||
service15 = 0x01,
|
||||
contract16 = 0x02,
|
||||
uri31 = 0x04
|
||||
}
|
||||
|
||||
internal EndpointPerformanceCountersBase(string service, string contract, string uri)
|
||||
{
|
||||
this.instanceName = CreateFriendlyInstanceName(service, contract, uri);
|
||||
}
|
||||
|
||||
private static string GetFullInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
// instance name is: serviceName.interfaceName.operationName@uri
|
||||
return String.Format("{0}.{1}@{2}", service, contract, uri);
|
||||
}
|
||||
|
||||
private static string GetShortInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
int length = service.Length + contract.Length + uri.Length + 2;
|
||||
|
||||
if (length > maxCounterLength)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
truncOptions tasks = EndpointPerformanceCounters.GetCompressionTasks(
|
||||
length, service.Length, contract.Length, uri.Length);
|
||||
|
||||
//if necessary, compress service name to 13 chars with a 2 char hash code
|
||||
if ((tasks & truncOptions.service15) > 0)
|
||||
{
|
||||
count = 15;
|
||||
service = GetHashedString(service, count - hashLength, service.Length - count + hashLength, true);
|
||||
}
|
||||
|
||||
//if necessary, compress contract name to 14 chars with a 2 char hash code
|
||||
if ((tasks & truncOptions.contract16) > 0)
|
||||
{
|
||||
count = 16;
|
||||
contract = GetHashedString(contract, count - hashLength, contract.Length - count + hashLength, true);
|
||||
}
|
||||
|
||||
//if necessary, compress uri to 29 chars with a 2 char hash code
|
||||
if ((tasks & truncOptions.uri31) > 0)
|
||||
{
|
||||
count = 31;
|
||||
uri = GetHashedString(uri, 0, uri.Length - count + hashLength, false);
|
||||
}
|
||||
}
|
||||
|
||||
// replace '/' with '|' because perfmon fails when '/' is in perfcounter instance name
|
||||
return service + "." + contract + "@" + uri.Replace('/', '|');
|
||||
}
|
||||
|
||||
internal static string CreateFriendlyInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, uri);
|
||||
|
||||
return EnsureUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
internal static string GetFriendlyInstanceName(string service, string contract, string uri)
|
||||
{
|
||||
string shortInstanceName = GetShortInstanceName(service, contract, uri);
|
||||
if (!ServiceModelAppSettings.EnsureUniquePerformanceCounterInstanceNames)
|
||||
{
|
||||
return shortInstanceName;
|
||||
}
|
||||
|
||||
string fullInstanceName = GetFullInstanceName(service, contract, uri);
|
||||
|
||||
return GetUniqueInstanceName(PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters, shortInstanceName, fullInstanceName);
|
||||
}
|
||||
|
||||
private static truncOptions GetCompressionTasks(int totalLen, int serviceLen, int contractLen, int uriLen)
|
||||
{
|
||||
truncOptions bitmask = 0;
|
||||
|
||||
if (totalLen > maxCounterLength)
|
||||
{
|
||||
int workingLen = totalLen;
|
||||
|
||||
//note: order of if statements important (see spec)!
|
||||
if (workingLen > maxCounterLength && serviceLen > 15)
|
||||
{
|
||||
bitmask |= truncOptions.service15; //compress service name to 16 chars
|
||||
workingLen -= serviceLen - 15;
|
||||
}
|
||||
if (workingLen > maxCounterLength && contractLen > 16)
|
||||
{
|
||||
bitmask |= truncOptions.contract16; //compress contract name to 8 chars
|
||||
workingLen -= contractLen - 16;
|
||||
}
|
||||
if (workingLen > maxCounterLength && uriLen > 31)
|
||||
{
|
||||
bitmask |= truncOptions.uri31; //compress uri to 31 chars
|
||||
}
|
||||
}
|
||||
|
||||
return bitmask;
|
||||
}
|
||||
|
||||
internal override string InstanceName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.instanceName;
|
||||
}
|
||||
}
|
||||
|
||||
internal override string[] CounterNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return perfCounterNames;
|
||||
}
|
||||
}
|
||||
|
||||
internal override int PerfCounterStart
|
||||
{
|
||||
get { return (int)PerfCounters.Calls; }
|
||||
}
|
||||
|
||||
internal override int PerfCounterEnd
|
||||
{
|
||||
get { return (int)PerfCounters.TotalCounters; }
|
||||
}
|
||||
|
||||
internal abstract void MethodCalled();
|
||||
|
||||
internal abstract void MethodReturnedSuccess();
|
||||
|
||||
internal abstract void MethodReturnedError();
|
||||
|
||||
internal abstract void MethodReturnedFault();
|
||||
|
||||
internal abstract void SaveCallDuration(long time);
|
||||
|
||||
internal abstract void AuthenticationFailed();
|
||||
|
||||
internal abstract void AuthorizationFailed();
|
||||
|
||||
internal abstract void SessionFaulted();
|
||||
|
||||
internal abstract void MessageDropped();
|
||||
|
||||
internal abstract void TxFlowed();
|
||||
}
|
||||
}
|
@@ -0,0 +1,191 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.PerformanceData;
|
||||
using System.Runtime;
|
||||
using System.Security;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Administration;
|
||||
|
||||
sealed class EndpointPerformanceCountersV2 : EndpointPerformanceCountersBase
|
||||
{
|
||||
static object syncRoot = new object();
|
||||
static Guid serviceModelProviderId = new Guid("{890c10c3-8c2a-4fe3-a36a-9eca153d47cb}");
|
||||
static Guid endpointCounterSetId = new Guid("{16dcff2c-91a3-4e6a-8135-0a9e6681c1b5}");
|
||||
|
||||
private static readonly CounterSetInstanceCache counterSetInstanceCache = new CounterSetInstanceCache();
|
||||
|
||||
// Double-checked locking pattern requires volatile for read/write synchronization
|
||||
static volatile CounterSet endpointCounterSet; // Defines the counter set
|
||||
CounterSetInstance endpointCounterSetInstance; // Instance of the counter set
|
||||
CounterData[] counters;
|
||||
|
||||
internal EndpointPerformanceCountersV2(string service, string contract, string uri)
|
||||
: base(service, contract, uri)
|
||||
{
|
||||
EnsureCounterSet();
|
||||
// Create an instance of the counter set (contains the counter data).
|
||||
this.endpointCounterSetInstance = CreateCounterSetInstance(this.InstanceName);
|
||||
this.counters = new CounterData[(int)PerfCounters.TotalCounters]; // Cache to dodge dictionary lookups in ServiceModelInstance
|
||||
for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
|
||||
{
|
||||
this.counters[i] = this.endpointCounterSetInstance.Counters[i];
|
||||
this.counters[i].Value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void EnsureCounterSet()
|
||||
{
|
||||
if (endpointCounterSet == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (endpointCounterSet == null)
|
||||
{
|
||||
CounterSet localCounterSet = CreateCounterSet();
|
||||
// Add the counters to the counter set definition.
|
||||
localCounterSet.AddCounter((int)PerfCounters.Calls, CounterType.RawData32, perfCounterNames[(int)PerfCounters.Calls]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsOutstanding, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsOutstanding]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsFailed, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsFailed]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsFailedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsFailedPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsFaulted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsFaulted]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsFaultedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsFaultedPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallDurationBase, CounterType.AverageBase, perfCounterNames[(int)PerfCounters.CallDurationBase]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallDuration, CounterType.AverageTimer32, perfCounterNames[(int)PerfCounters.CallDuration]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.SecurityValidationAuthenticationFailures, CounterType.RawData32, perfCounterNames[(int)PerfCounters.SecurityValidationAuthenticationFailures]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsNotAuthorized, CounterType.RawData32, perfCounterNames[(int)PerfCounters.CallsNotAuthorized]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.CallsNotAuthorizedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.CallsNotAuthorizedPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.RMSessionsFaulted, CounterType.RawData32, perfCounterNames[(int)PerfCounters.RMSessionsFaulted]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.RMSessionsFaultedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.RMSessionsFaultedPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.RMMessagesDropped, CounterType.RawData32, perfCounterNames[(int)PerfCounters.RMMessagesDropped]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.RMMessagesDroppedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.RMMessagesDroppedPerSecond]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.TxFlowed, CounterType.RawData32, perfCounterNames[(int)PerfCounters.TxFlowed]);
|
||||
localCounterSet.AddCounter((int)PerfCounters.TxFlowedPerSecond, CounterType.RateOfCountPerSecond32, perfCounterNames[(int)PerfCounters.TxFlowedPerSecond]);
|
||||
endpointCounterSet = localCounterSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Calls into Sys.Diag.PerformanceData.CounterSet..ctor marked as SecurityCritical", Safe = "No user provided data is passed to the call")]
|
||||
[SecuritySafeCritical]
|
||||
static CounterSet CreateCounterSet()
|
||||
{
|
||||
return new CounterSet(serviceModelProviderId, endpointCounterSetId, CounterSetInstanceType.Multiple);
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "Calls into Sys.Diag.PerformanceData.CounterSetInstance.CreateCounterSetInstance marked as SecurityCritical", Safe = "No user provided data is passed to the call, instance name parameter is generated by Sys.ServiceModel.Diagnostics code from service description")]
|
||||
[SecuritySafeCritical]
|
||||
static CounterSetInstance CreateCounterSetInstance(string name)
|
||||
{
|
||||
return counterSetInstanceCache.Get(name) ?? endpointCounterSet.CreateCounterSetInstance(name);
|
||||
}
|
||||
|
||||
internal override void MethodCalled()
|
||||
{
|
||||
this.counters[(int)PerfCounters.Calls].Increment();
|
||||
this.counters[(int)PerfCounters.CallsPerSecond].Increment();
|
||||
this.counters[(int)PerfCounters.CallsOutstanding].Increment();
|
||||
}
|
||||
|
||||
internal override void MethodReturnedSuccess()
|
||||
{
|
||||
this.counters[(int)PerfCounters.CallsOutstanding].Decrement();
|
||||
}
|
||||
|
||||
internal override void MethodReturnedError()
|
||||
{
|
||||
this.counters[(int)PerfCounters.CallsFailed].Increment();
|
||||
this.counters[(int)PerfCounters.CallsFailedPerSecond].Increment();
|
||||
this.counters[(int)PerfCounters.CallsOutstanding].Decrement();
|
||||
}
|
||||
|
||||
internal override void MethodReturnedFault()
|
||||
{
|
||||
this.counters[(int)PerfCounters.CallsFaulted].Increment();
|
||||
this.counters[(int)PerfCounters.CallsFaultedPerSecond].Increment();
|
||||
this.counters[(int)PerfCounters.CallsOutstanding].Decrement();
|
||||
}
|
||||
|
||||
internal override void SaveCallDuration(long time)
|
||||
{
|
||||
this.counters[(int)PerfCounters.CallDuration].IncrementBy(time);
|
||||
this.counters[(int)PerfCounters.CallDurationBase].Increment();
|
||||
}
|
||||
|
||||
internal override void AuthenticationFailed()
|
||||
{
|
||||
this.counters[(int)PerfCounters.SecurityValidationAuthenticationFailures].Increment();
|
||||
this.counters[(int)PerfCounters.SecurityValidationAuthenticationFailuresPerSecond].Increment();
|
||||
}
|
||||
|
||||
internal override void AuthorizationFailed()
|
||||
{
|
||||
this.counters[(int)PerfCounters.CallsNotAuthorized].Increment();
|
||||
this.counters[(int)PerfCounters.CallsNotAuthorizedPerSecond].Increment();
|
||||
}
|
||||
|
||||
internal override void SessionFaulted()
|
||||
{
|
||||
this.counters[(int)PerfCounters.RMSessionsFaulted].Increment();
|
||||
this.counters[(int)PerfCounters.RMSessionsFaultedPerSecond].Increment();
|
||||
}
|
||||
|
||||
internal override void MessageDropped()
|
||||
{
|
||||
this.counters[(int)PerfCounters.RMMessagesDropped].Increment();
|
||||
this.counters[(int)PerfCounters.RMMessagesDroppedPerSecond].Increment();
|
||||
}
|
||||
|
||||
internal override void TxFlowed()
|
||||
{
|
||||
this.counters[(int)PerfCounters.TxFlowed].Increment();
|
||||
this.counters[(int)PerfCounters.TxFlowedPerSecond].Increment();
|
||||
}
|
||||
|
||||
internal override bool Initialized
|
||||
{
|
||||
get { return this.endpointCounterSetInstance != null; }
|
||||
}
|
||||
|
||||
// Immediately disposes and nulls the CounterSetInstance. This differs from Dispose because Dispose is "lazy" in that
|
||||
// it holds weak references to the instances so we don't get corrupted state if the values are updated later. This
|
||||
// method is used in situations when we need to delete the instance immediately and know the values won't be updated.
|
||||
internal void DeleteInstance()
|
||||
{
|
||||
if (this.endpointCounterSetInstance != null)
|
||||
{
|
||||
this.endpointCounterSetInstance.Dispose();
|
||||
this.endpointCounterSetInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing && PerformanceCounters.PerformanceCountersEnabled && this.endpointCounterSetInstance != null)
|
||||
{
|
||||
counterSetInstanceCache.Add(this.InstanceName, this.endpointCounterSetInstance);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Not really necessary as base.Dispose() does nothing
|
||||
// But forced to leave this with try/finally by unability to suspend FxCop 1.35 warning
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CleanupCache()
|
||||
{
|
||||
counterSetInstanceCache.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
// <copyright>
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
internal static class EventTraceActivityHelper
|
||||
{
|
||||
public static bool TryAttachActivity(Message message, EventTraceActivity activity)
|
||||
{
|
||||
if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled && (message != null) && (activity != null))
|
||||
{
|
||||
if (!message.Properties.ContainsKey(EventTraceActivity.Name))
|
||||
{
|
||||
message.Properties.Add(EventTraceActivity.Name, activity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static EventTraceActivity TryExtractActivity(Message message)
|
||||
{
|
||||
return TryExtractActivity(message, false);
|
||||
}
|
||||
|
||||
public static EventTraceActivity TryExtractActivity(Message message, bool createIfNotExist)
|
||||
{
|
||||
EventTraceActivity eventTraceActivity = null;
|
||||
|
||||
if (message != null && message.State != MessageState.Closed)
|
||||
{
|
||||
object property;
|
||||
if (message.Properties.TryGetValue(EventTraceActivity.Name, out property))
|
||||
{
|
||||
eventTraceActivity = property as EventTraceActivity;
|
||||
}
|
||||
|
||||
if (eventTraceActivity == null)
|
||||
{
|
||||
Guid activityId;
|
||||
if (GetMessageId(message, out activityId))
|
||||
{
|
||||
eventTraceActivity = new EventTraceActivity(activityId);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniqueId uid = message.Headers.RelatesTo;
|
||||
if (uid != null)
|
||||
{
|
||||
if (uid.TryGetGuid(out activityId))
|
||||
{
|
||||
eventTraceActivity = new EventTraceActivity(activityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventTraceActivity == null && createIfNotExist)
|
||||
{
|
||||
eventTraceActivity = new EventTraceActivity();
|
||||
}
|
||||
|
||||
if (eventTraceActivity != null)
|
||||
{
|
||||
// Attach the trace activity to the message
|
||||
message.Properties[EventTraceActivity.Name] = eventTraceActivity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eventTraceActivity;
|
||||
}
|
||||
|
||||
[Fx.Tag.SecurityNote(Critical = "This sets the ActivityId on the thread. Must not be settable from PT code unless from safe context.")]
|
||||
[SecurityCritical]
|
||||
[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
|
||||
internal static void SetOnThread(EventTraceActivity eventTraceActivity)
|
||||
{
|
||||
if (eventTraceActivity != null)
|
||||
{
|
||||
Trace.CorrelationManager.ActivityId = eventTraceActivity.ActivityId;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GetMessageId(Message message, out Guid guid)
|
||||
{
|
||||
UniqueId uniqueId = message.Headers.MessageId;
|
||||
if (uniqueId == null)
|
||||
{
|
||||
guid = Guid.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniqueId.TryGetGuid(out guid);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.Xml;
|
||||
|
||||
class HttpErrorTraceRecord : TraceRecord
|
||||
{
|
||||
string html;
|
||||
|
||||
internal HttpErrorTraceRecord(string html)
|
||||
{
|
||||
this.html = XmlEncode(html);
|
||||
}
|
||||
|
||||
internal override string EventId
|
||||
{
|
||||
get { return BuildEventId("HttpError"); }
|
||||
}
|
||||
|
||||
internal override void WriteTo(XmlWriter writer)
|
||||
{
|
||||
writer.WriteElementString("HtmlErrorMessage", html);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Net;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.Xml;
|
||||
|
||||
class HttpListenerRequestTraceRecord : TraceRecord
|
||||
{
|
||||
HttpListenerRequest request;
|
||||
|
||||
internal HttpListenerRequestTraceRecord(HttpListenerRequest request)
|
||||
{
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("HttpRequest"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("Headers");
|
||||
foreach (string key in this.request.Headers.Keys)
|
||||
{
|
||||
writer.WriteElementString(key, this.request.Headers[key]);
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
writer.WriteElementString("Url", this.request.Url.ToString());
|
||||
if (this.request.QueryString != null && this.request.QueryString.Count > 0)
|
||||
{
|
||||
writer.WriteStartElement("QueryString");
|
||||
foreach (string key in this.request.QueryString.Keys)
|
||||
{
|
||||
writer.WriteElementString(key, this.request.Headers[key]);
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
sealed class MessageDroppedTraceRecord : MessageTraceRecord
|
||||
{
|
||||
EndpointAddress endpointAddress;
|
||||
internal MessageDroppedTraceRecord(Message message, EndpointAddress endpointAddress) :
|
||||
base(message)
|
||||
{
|
||||
this.endpointAddress = endpointAddress;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("MessageDropped"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
base.WriteTo(xml);
|
||||
if (this.endpointAddress != null)
|
||||
{
|
||||
xml.WriteStartElement("EndpointAddress");
|
||||
this.endpointAddress.WriteTo(AddressingVersion.WSAddressing10, xml);
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
sealed class MessageHeaderInfoTraceRecord : TraceRecord
|
||||
{
|
||||
MessageHeaderInfo messageHeaderInfo;
|
||||
internal MessageHeaderInfoTraceRecord(MessageHeaderInfo messageHeaderInfo)
|
||||
{
|
||||
this.messageHeaderInfo = messageHeaderInfo;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("MessageHeaderInfo"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
if (this.messageHeaderInfo != null)
|
||||
{
|
||||
xml.WriteStartElement("MessageHeaderInfo");
|
||||
if (!string.IsNullOrEmpty(this.messageHeaderInfo.Actor))
|
||||
{
|
||||
xml.WriteElementString("Actor", this.messageHeaderInfo.Actor);
|
||||
}
|
||||
xml.WriteElementString("MustUnderstand", this.messageHeaderInfo.MustUnderstand.ToString());
|
||||
if (!string.IsNullOrEmpty(this.messageHeaderInfo.Name))
|
||||
{
|
||||
xml.WriteElementString("Name", this.messageHeaderInfo.Name);
|
||||
}
|
||||
xml.WriteElementString("Relay", this.messageHeaderInfo.Relay.ToString());
|
||||
if (!string.IsNullOrEmpty(this.messageHeaderInfo.Namespace))
|
||||
{
|
||||
xml.WriteElementString("Namespace", this.messageHeaderInfo.Namespace);
|
||||
}
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,349 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Security;
|
||||
using System.Xml;
|
||||
|
||||
sealed class MessageLogTraceRecord : TraceRecord
|
||||
{
|
||||
internal const string AddressingElementName = "Addressing";
|
||||
internal const string BodyElementName = "Body";
|
||||
internal const string HttpRequestMessagePropertyElementName = "HttpRequest";
|
||||
internal const string HttpResponseMessagePropertyElementName = "HttpResponse";
|
||||
internal const string NamespaceUri = "http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace";
|
||||
internal const string NamespacePrefix = "";
|
||||
internal const string MessageHeaderElementName = "Header";
|
||||
internal const string MessageHeadersElementName = "MessageHeaders";
|
||||
internal const string MessageLogTraceRecordElementName = "MessageLogTraceRecord";
|
||||
internal const string MethodElementName = "Method";
|
||||
internal const string QueryStringElementName = "QueryString";
|
||||
internal const string StatusCodeElementName = "StatusCode";
|
||||
internal const string StatusDescriptionElementName = "StatusDescription";
|
||||
internal const string TraceTimeAttributeName = "Time";
|
||||
internal const string TypeElementName = "Type";
|
||||
internal const string WebHeadersElementName = "WebHeaders";
|
||||
|
||||
|
||||
Message message;
|
||||
XmlReader reader;
|
||||
string messageString;
|
||||
DateTime timestamp;
|
||||
bool logMessageBody = true;
|
||||
MessageLoggingSource source;
|
||||
Type type;
|
||||
|
||||
MessageLogTraceRecord(MessageLoggingSource source)
|
||||
{
|
||||
this.source = source;
|
||||
this.timestamp = DateTime.Now;
|
||||
}
|
||||
|
||||
internal MessageLogTraceRecord(ArraySegment<byte> buffer, MessageLoggingSource source)
|
||||
: this(source)
|
||||
{
|
||||
this.type = null;
|
||||
this.messageString = System.Text.Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count);
|
||||
}
|
||||
|
||||
internal MessageLogTraceRecord(string message, MessageLoggingSource source)
|
||||
: this(source)
|
||||
{
|
||||
this.type = null;
|
||||
this.messageString = message;
|
||||
}
|
||||
|
||||
internal MessageLogTraceRecord(Stream stream, MessageLoggingSource source)
|
||||
: this(source)
|
||||
{
|
||||
this.type = null;
|
||||
|
||||
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
|
||||
StreamReader streamReader = new StreamReader(stream);
|
||||
|
||||
int chunkSize = 4096;
|
||||
char[] buffer = DiagnosticUtility.Utility.AllocateCharArray(chunkSize);
|
||||
int count = MessageLogger.MaxMessageSize;
|
||||
|
||||
if (-1 == count)
|
||||
{
|
||||
count = 4096; //Can't buffer potentially unbounded stream, let's get 4K hoping it will help
|
||||
}
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
int charsRead = streamReader.Read(buffer, 0, chunkSize);
|
||||
if (charsRead == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
int charsToAppend = count < charsRead ? count : charsRead;
|
||||
stringBuilder.Append(buffer, 0, charsToAppend);
|
||||
count -= charsRead;
|
||||
}
|
||||
|
||||
streamReader.Close();
|
||||
|
||||
this.messageString = stringBuilder.ToString();
|
||||
}
|
||||
|
||||
internal MessageLogTraceRecord(ref Message message, XmlReader reader, MessageLoggingSource source, bool logMessageBody)
|
||||
: this(source)
|
||||
{
|
||||
Fx.Assert(message != null, "");
|
||||
|
||||
MessageBuffer buffer = null;
|
||||
|
||||
try
|
||||
{
|
||||
this.logMessageBody = logMessageBody;
|
||||
this.message = message;
|
||||
this.reader = reader;
|
||||
this.type = message.GetType();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (buffer != null)
|
||||
{
|
||||
buffer.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Message Message
|
||||
{
|
||||
get { return this.message; }
|
||||
}
|
||||
|
||||
public MessageLoggingSource MessageLoggingSource
|
||||
{
|
||||
get { return this.source; }
|
||||
}
|
||||
|
||||
internal override void WriteTo(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement(MessageLogTraceRecord.NamespacePrefix, MessageLogTraceRecord.MessageLogTraceRecordElementName, MessageLogTraceRecord.NamespaceUri); // <MessageLogTraceRecord>
|
||||
writer.WriteAttributeString(MessageLogTraceRecord.TraceTimeAttributeName, this.timestamp.ToString("o", CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString(DiagnosticStrings.SourceTag, this.source.ToString());
|
||||
|
||||
if (null != this.type)
|
||||
{
|
||||
Fx.Assert(this.message != null, "");
|
||||
|
||||
XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);
|
||||
dictionaryWriter.WriteAttributeString(MessageLogTraceRecord.TypeElementName, this.type.ToString());
|
||||
|
||||
#if DEBUG
|
||||
MessageProperties properties = this.message.Properties;
|
||||
dictionaryWriter.WriteStartElement("Properties");
|
||||
foreach (string key in properties.Keys)
|
||||
{
|
||||
dictionaryWriter.WriteElementString(key, properties[key].ToString());
|
||||
}
|
||||
dictionaryWriter.WriteEndElement(); // </Properties>
|
||||
#endif
|
||||
WriteAddressingProperties(dictionaryWriter);
|
||||
WriteHttpProperties(dictionaryWriter);
|
||||
|
||||
if (null != this.reader) //TransportSend case: Message may miss some security data, so we use XmlReader created from serialized message
|
||||
{
|
||||
this.reader.MoveToContent();
|
||||
}
|
||||
if (this.logMessageBody)
|
||||
{
|
||||
if (null != this.reader)
|
||||
{
|
||||
dictionaryWriter.WriteNode(this.reader, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasAtLeastOneItemInsideSecurityHeaderEncrypted = false;
|
||||
|
||||
if (this.message is SecurityVerifiedMessage)
|
||||
{
|
||||
SecurityVerifiedMessage verifiedMessage = this.message as SecurityVerifiedMessage;
|
||||
ReceiveSecurityHeader receivedHeader = verifiedMessage.ReceivedSecurityHeader;
|
||||
hasAtLeastOneItemInsideSecurityHeaderEncrypted = receivedHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted;
|
||||
}
|
||||
|
||||
if (!hasAtLeastOneItemInsideSecurityHeaderEncrypted)
|
||||
{
|
||||
this.message.ToString(dictionaryWriter);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.message.Version.Envelope != EnvelopeVersion.None)
|
||||
{
|
||||
dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace);
|
||||
WriteHeader(dictionaryWriter);
|
||||
this.message.WriteStartBody(writer);
|
||||
}
|
||||
|
||||
this.message.BodyToString(dictionaryWriter);
|
||||
|
||||
if (this.message.Version.Envelope != EnvelopeVersion.None)
|
||||
{
|
||||
writer.WriteEndElement(); // </Body>
|
||||
dictionaryWriter.WriteEndElement(); // </Envelope>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.message.Version.Envelope != EnvelopeVersion.None) //No headers for EnvelopeVersion.None
|
||||
{
|
||||
if (null != this.reader)
|
||||
{
|
||||
dictionaryWriter.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
|
||||
this.reader.Read();
|
||||
if (0 == String.CompareOrdinal(reader.LocalName, "Header"))
|
||||
{
|
||||
dictionaryWriter.WriteNode(this.reader, true);
|
||||
}
|
||||
dictionaryWriter.WriteEndElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Envelope, this.message.Version.Envelope.DictionaryNamespace);
|
||||
WriteHeader(dictionaryWriter);
|
||||
dictionaryWriter.WriteEndElement(); // </Envelope>
|
||||
}
|
||||
}
|
||||
if (null != this.reader)
|
||||
{
|
||||
this.reader.Close();
|
||||
this.reader = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteCData(this.messageString);
|
||||
}
|
||||
writer.WriteEndElement(); // </MessageLogTraceRecord>
|
||||
}
|
||||
|
||||
void WriteHeader(XmlDictionaryWriter dictionaryWriter)
|
||||
{
|
||||
dictionaryWriter.WriteStartElement(XD.MessageDictionary.Prefix.Value, XD.MessageDictionary.Header, this.message.Version.Envelope.DictionaryNamespace);
|
||||
MessageHeaders headers = this.message.Headers;
|
||||
Security.ReceiveSecurityHeader receivedHeader = null;
|
||||
|
||||
if (this.message is SecurityVerifiedMessage)
|
||||
{
|
||||
SecurityVerifiedMessage verifiedMessage = this.message as SecurityVerifiedMessage;
|
||||
receivedHeader = verifiedMessage.ReceivedSecurityHeader;
|
||||
}
|
||||
|
||||
for (int i = 0; i < headers.Count; ++i)
|
||||
{
|
||||
if (receivedHeader != null && receivedHeader.HasAtLeastOneItemInsideSecurityHeaderEncrypted && receivedHeader.HeaderIndex == i)
|
||||
{
|
||||
//
|
||||
// if this is the security header and we found at least one item
|
||||
// was encrypted inside the security header
|
||||
//
|
||||
receivedHeader.WriteStartHeader(dictionaryWriter, headers.MessageVersion);
|
||||
receivedHeader.WriteHeaderContents(dictionaryWriter, headers.MessageVersion);
|
||||
dictionaryWriter.WriteEndElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.WriteHeader(i, dictionaryWriter);
|
||||
}
|
||||
}
|
||||
dictionaryWriter.WriteEndElement(); // </Headers>
|
||||
}
|
||||
|
||||
|
||||
void WriteAddressingProperties(XmlWriter dictionaryWriter)
|
||||
{
|
||||
Fx.Assert(this.message != null, "");
|
||||
object property;
|
||||
if (this.message.Properties.TryGetValue(AddressingProperty.Name, out property))
|
||||
{
|
||||
AddressingProperty addressingProperty = (AddressingProperty)property;
|
||||
|
||||
dictionaryWriter.WriteStartElement(MessageLogTraceRecord.AddressingElementName);
|
||||
|
||||
dictionaryWriter.WriteElementString(AddressingStrings.Action, addressingProperty.Action);
|
||||
if (null != addressingProperty.ReplyTo)
|
||||
{
|
||||
dictionaryWriter.WriteElementString(AddressingStrings.ReplyTo, addressingProperty.ReplyTo.ToString());
|
||||
}
|
||||
if (null != addressingProperty.To)
|
||||
{
|
||||
dictionaryWriter.WriteElementString(AddressingStrings.To, addressingProperty.To.AbsoluteUri);
|
||||
}
|
||||
if (null != addressingProperty.MessageId)
|
||||
{
|
||||
dictionaryWriter.WriteElementString(AddressingStrings.MessageId, addressingProperty.MessageId.ToString());
|
||||
}
|
||||
|
||||
dictionaryWriter.WriteEndElement(); // Addressing
|
||||
|
||||
message.Properties.Remove(AddressingProperty.Name);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteHttpProperties(XmlWriter dictionaryWriter)
|
||||
{
|
||||
Fx.Assert(this.message != null, "");
|
||||
object property;
|
||||
if (this.message.Properties.TryGetValue(HttpResponseMessageProperty.Name, out property))
|
||||
{
|
||||
HttpResponseMessageProperty responseProperty = (HttpResponseMessageProperty)property;
|
||||
|
||||
dictionaryWriter.WriteStartElement(MessageLogTraceRecord.HttpResponseMessagePropertyElementName);
|
||||
|
||||
dictionaryWriter.WriteElementString(MessageLogTraceRecord.StatusCodeElementName, responseProperty.StatusCode.ToString());
|
||||
if (responseProperty.StatusDescription != null)
|
||||
{
|
||||
dictionaryWriter.WriteElementString(MessageLogTraceRecord.StatusDescriptionElementName, responseProperty.StatusDescription);
|
||||
}
|
||||
|
||||
dictionaryWriter.WriteStartElement(MessageLogTraceRecord.WebHeadersElementName);
|
||||
WebHeaderCollection responseHeaders = responseProperty.Headers;
|
||||
for (int i = 0; i < responseHeaders.Count; i++)
|
||||
{
|
||||
string name = responseHeaders.Keys[i];
|
||||
string value = responseHeaders[i];
|
||||
dictionaryWriter.WriteElementString(name, value);
|
||||
}
|
||||
dictionaryWriter.WriteEndElement(); //
|
||||
|
||||
dictionaryWriter.WriteEndElement(); // </HttpResponseMessageProperty>
|
||||
}
|
||||
|
||||
if (this.message.Properties.TryGetValue(HttpRequestMessageProperty.Name, out property))
|
||||
{
|
||||
HttpRequestMessageProperty requestProperty = (HttpRequestMessageProperty)property;
|
||||
|
||||
dictionaryWriter.WriteStartElement(MessageLogTraceRecord.HttpRequestMessagePropertyElementName);
|
||||
|
||||
dictionaryWriter.WriteElementString(MessageLogTraceRecord.MethodElementName, requestProperty.Method);
|
||||
dictionaryWriter.WriteElementString(MessageLogTraceRecord.QueryStringElementName, requestProperty.QueryString);
|
||||
|
||||
dictionaryWriter.WriteStartElement(MessageLogTraceRecord.WebHeadersElementName);
|
||||
WebHeaderCollection responseHeaders = requestProperty.Headers;
|
||||
for (int i = 0; i < responseHeaders.Count; i++)
|
||||
{
|
||||
string name = responseHeaders.Keys[i];
|
||||
string value = responseHeaders[i];
|
||||
dictionaryWriter.WriteElementString(name, value);
|
||||
}
|
||||
dictionaryWriter.WriteEndElement(); //
|
||||
|
||||
dictionaryWriter.WriteEndElement(); // </HttpResponseMessageProperty>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
using System.Xml;
|
||||
|
||||
class MessageLoggingFilterTraceRecord : TraceRecord
|
||||
{
|
||||
XPathMessageFilter filter;
|
||||
|
||||
internal MessageLoggingFilterTraceRecord(XPathMessageFilter filter)
|
||||
{
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("MessageLoggingFilter"); } }
|
||||
|
||||
internal override void WriteTo(XmlWriter writer)
|
||||
{
|
||||
filter.WriteXPathTo(writer, "", "Filter", "", false);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.IdentityModel.Claims;
|
||||
using System.IdentityModel.Policy;
|
||||
using System.Runtime;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class MessageTraceRecord : TraceRecord
|
||||
{
|
||||
Message message;
|
||||
internal MessageTraceRecord(Message message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
internal override string EventId
|
||||
{
|
||||
get { return BuildEventId("Message"); }
|
||||
}
|
||||
|
||||
protected Message Message
|
||||
{
|
||||
get { return this.message; }
|
||||
}
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
if ((this.message != null) &&
|
||||
(this.message.State != MessageState.Closed) &&
|
||||
(this.message.Headers != null))
|
||||
{
|
||||
try
|
||||
{
|
||||
xml.WriteStartElement("MessageProperties");
|
||||
if (message.Properties.Encoder != null)
|
||||
{
|
||||
xml.WriteElementString("Encoder", message.Properties.Encoder.ToString());
|
||||
}
|
||||
xml.WriteElementString("AllowOutputBatching", message.Properties.AllowOutputBatching.ToString());
|
||||
if (message.Properties.Security != null && message.Properties.Security.ServiceSecurityContext != null)
|
||||
{
|
||||
xml.WriteStartElement("Security");
|
||||
xml.WriteElementString("IsAnonymous", message.Properties.Security.ServiceSecurityContext.IsAnonymous.ToString());
|
||||
bool windowsIdentityUsed = message.Properties.Security.ServiceSecurityContext.WindowsIdentity != null &&
|
||||
!string.IsNullOrEmpty(message.Properties.Security.ServiceSecurityContext.WindowsIdentity.Name);
|
||||
xml.WriteElementString("WindowsIdentityUsed", windowsIdentityUsed.ToString());
|
||||
if (DiagnosticUtility.ShouldTraceVerbose)
|
||||
{
|
||||
xml.WriteStartElement("Claims");
|
||||
AuthorizationContext authContext = message.Properties.Security.ServiceSecurityContext.AuthorizationContext;
|
||||
for (int i = 0; i < authContext.ClaimSets.Count; ++i)
|
||||
{
|
||||
ClaimSet claimSet = authContext.ClaimSets[i];
|
||||
xml.WriteStartElement("ClaimSet");
|
||||
xml.WriteAttributeString("ClrType", base.XmlEncode(claimSet.GetType().AssemblyQualifiedName));
|
||||
|
||||
for (int j = 0; j < claimSet.Count; ++j)
|
||||
{
|
||||
Fx.Assert(null != claimSet[j], "Claim cannot be null");
|
||||
SecurityTraceRecordHelper.WriteClaim(xml, claimSet[j]);
|
||||
}
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
|
||||
if (message.Properties.Via != null)
|
||||
{
|
||||
xml.WriteElementString("Via", message.Properties.Via.ToString());
|
||||
}
|
||||
|
||||
xml.WriteEndElement();
|
||||
|
||||
xml.WriteStartElement(MessageLogTraceRecord.MessageHeadersElementName);
|
||||
for (int i = 0; i < this.message.Headers.Count; i++)
|
||||
{
|
||||
this.message.Headers.WriteHeader(i, xml);
|
||||
}
|
||||
|
||||
xml.WriteEndElement();
|
||||
}
|
||||
catch (CommunicationException e)
|
||||
{
|
||||
if (DiagnosticUtility.ShouldTraceInformation)
|
||||
{
|
||||
TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.DiagnosticsFailedMessageTrace,
|
||||
SR.GetString(SR.TraceCodeDiagnosticsFailedMessageTrace), e, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class MessageTransmitTraceRecord : MessageTraceRecord
|
||||
{
|
||||
Uri address = null;
|
||||
string addressElementName = null;
|
||||
|
||||
MessageTransmitTraceRecord(Message message) : base(message) { }
|
||||
|
||||
MessageTransmitTraceRecord(Message message, string addressElementName)
|
||||
:
|
||||
this(message)
|
||||
{
|
||||
this.addressElementName = addressElementName;
|
||||
}
|
||||
|
||||
MessageTransmitTraceRecord(Message message, string addressElementName, EndpointAddress address)
|
||||
:
|
||||
this(message, addressElementName)
|
||||
{
|
||||
if (address != null)
|
||||
{
|
||||
this.address = address.Uri;
|
||||
}
|
||||
}
|
||||
|
||||
MessageTransmitTraceRecord(Message message, string addressElementName, Uri uri)
|
||||
:
|
||||
this(message, addressElementName)
|
||||
{
|
||||
this.address = uri;
|
||||
}
|
||||
|
||||
internal override string EventId { get { return BuildEventId("MessageTransmit"); } }
|
||||
|
||||
internal static MessageTransmitTraceRecord CreateSendTraceRecord(Message message, EndpointAddress address)
|
||||
{
|
||||
return new MessageTransmitTraceRecord(message, "RemoteAddress", address);
|
||||
}
|
||||
|
||||
internal static MessageTransmitTraceRecord CreateReceiveTraceRecord(Message message, Uri uri)
|
||||
{
|
||||
return new MessageTransmitTraceRecord(message, "LocalAddress", uri);
|
||||
}
|
||||
|
||||
internal static MessageTransmitTraceRecord CreateReceiveTraceRecord(Message message, EndpointAddress address)
|
||||
{
|
||||
return new MessageTransmitTraceRecord(message, "LocalAddress", address);
|
||||
}
|
||||
|
||||
internal static MessageTransmitTraceRecord CreateReceiveTraceRecord(Message message)
|
||||
{
|
||||
return new MessageTransmitTraceRecord(message);
|
||||
}
|
||||
|
||||
internal override void WriteTo(XmlWriter xml)
|
||||
{
|
||||
base.WriteTo(xml);
|
||||
if (this.address != null)
|
||||
{
|
||||
xml.WriteElementString(this.addressElementName, this.address.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
#if USE_REFEMIT
|
||||
public static class OperationInvokerTrace
|
||||
#else
|
||||
static class OperationInvokerTrace
|
||||
#endif
|
||||
{
|
||||
static TraceSource codeGenSource;
|
||||
static MethodInfo traceInstructionMethod;
|
||||
|
||||
internal static SourceSwitch CodeGenerationSwitch
|
||||
{
|
||||
get { return CodeGenerationTraceSource.Switch; }
|
||||
}
|
||||
|
||||
internal static void WriteInstruction(int lineNumber, string instruction)
|
||||
{
|
||||
CodeGenerationTraceSource.TraceInformation("{0:00000}: {1}", lineNumber, instruction);
|
||||
}
|
||||
|
||||
internal static MethodInfo TraceInstructionMethod
|
||||
{
|
||||
get
|
||||
{
|
||||
if (traceInstructionMethod == null)
|
||||
traceInstructionMethod = typeof(OperationInvokerTrace).GetMethod("TraceInstruction", BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
return traceInstructionMethod;
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_REFEMIT
|
||||
public static void TraceInstruction(string instruction)
|
||||
#else
|
||||
internal static void TraceInstruction(string instruction)
|
||||
#endif
|
||||
{
|
||||
CodeGenerationTraceSource.TraceEvent(TraceEventType.Verbose, 0, instruction);
|
||||
}
|
||||
|
||||
static TraceSource CodeGenerationTraceSource
|
||||
{
|
||||
get
|
||||
{
|
||||
if (codeGenSource == null)
|
||||
codeGenSource = new TraceSource("System.ServiceModel.OperationInvoker.CodeGeneration");
|
||||
return codeGenSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user