protected TrackingRecord(Guid instanceId)
 {
     this.InstanceId = instanceId;
     this.EventTime = DateTime.UtcNow;
     this.Level = TraceLevel.Info;
     this.eventTraceActivity = new EventTraceActivity(instanceId);
 }
        internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, Guid value1, string value2, string value3)
        {
            const int argumentCount = 3;
            bool status = true;

            //check all strings for null            
            value2 = (value2 ?? string.Empty);
            value3 = (value3 ?? string.Empty);

            fixed (char* string1Bytes = value2, string2Bytes = value3)
            {
                byte* eventData = stackalloc byte[sizeof(UnsafeNativeMethods.EventData) * argumentCount];
                UnsafeNativeMethods.EventData* eventDataPtr = (UnsafeNativeMethods.EventData*)eventData;

                eventDataPtr[0].DataPointer = (ulong)(&value1);
                eventDataPtr[0].Size = (uint)(sizeof(Guid));

                eventDataPtr[1].DataPointer = (ulong)string1Bytes;
                eventDataPtr[1].Size = (uint)(value2.Length + 1) * sizeof(char);
            
                eventDataPtr[2].DataPointer = (ulong)string2Bytes;
                eventDataPtr[2].Size = (uint)(value3.Length + 1) * sizeof(char);                

                status = WriteEvent(ref eventDescriptor, eventTraceActivity, argumentCount, (IntPtr)(eventData));
            }

            return status;
        }
Beispiel #3
0
 /// <summary>
 /// Gets trace definition like: IO Thread scheduler callback invoked.
 /// Event description ID=133, Level=verbose, Channel=Debug
 /// </summary>
 /// <param name="trace">The trace provider</param>
 /// <param name="eventTraceActivity">The event trace activity</param>
 internal static void ActionItemScheduled(EtwDiagnosticTrace trace, System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
 {
     TracePayload payload = trace.GetSerializedPayload(null, null, null);
     if (TraceCore.IsEtwEventEnabled(trace, 13))
     {
         TraceCore.WriteEtwEvent(trace, 13, eventTraceActivity, payload.AppDomainFriendlyName);
     }
 }
Beispiel #4
0
		internal static void ActionItemScheduled(EtwDiagnosticTrace trace, EventTraceActivity eventTraceActivity)
		{
			TracePayload serializedPayload = trace.GetSerializedPayload(null, null, null);
			if (TraceCore.IsEtwEventEnabled(trace, 13))
			{
				TraceCore.WriteEtwEvent(trace, 13, eventTraceActivity, serializedPayload.AppDomainFriendlyName);
			}
		}
        /// <summary>
        /// Gets trace definition like: {0} idle services out of total {1} activated services closed.
        /// Event description ID=226, Level=LogAlways, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="ClosedCount">Parameter 0 for event: {0} idle services out of total {1} activated services closed.</param>
        /// <param name="TotalCount">Parameter 1 for event: {0} idle services out of total {1} activated services closed.</param>
        internal static void IdleServicesClosed(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, int ClosedCount, int TotalCount)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(13))
            {
                TD.WriteEtwEvent(13, eventTraceActivity, ClosedCount, TotalCount, payload.AppDomainFriendlyName);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets trace definition like: Tcp transport listener starting to listen on uri:'{0}'.
        /// Event description ID=4020, Level=Verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="Uri">Parameter 0 for event: Tcp transport listener starting to listen on uri:'{0}'.</param>
        internal static void TcpTransportListenerListeningStart(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string Uri)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(12))
            {
                TD.WriteEtwEvent(12, eventTraceActivity, Uri, payload.AppDomainFriendlyName);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets trace definition like: MessageQueueDuplicatedSocketComplete
        /// Event description ID=4019, Level=Verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void MessageQueueDuplicatedSocketComplete(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(11))
            {
                TD.WriteEtwEvent(11, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Gets trace definition like: Message queue unregister succeeded for uri:'{0}'.
        /// Event description ID=4013, Level=verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="Uri">Parameter 0 for event: Message queue unregister succeeded for uri:'{0}'.</param>
        internal static void MessageQueueUnregisterSucceeded(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string Uri)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(9))
            {
                TD.WriteEtwEvent(9, eventTraceActivity, Uri, payload.AppDomainFriendlyName);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Gets trace definition like: Message queue registration for uri:'{0}' failed with status:'{1}'.
        /// Event description ID=4014, Level=Error, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="Uri">Parameter 0 for event: Message queue registration for uri:'{0}' failed with status:'{1}'.</param>
        /// <param name="Status">Parameter 1 for event: Message queue registration for uri:'{0}' failed with status:'{1}'.</param>
        internal static void MessageQueueRegisterFailed(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string Uri, string Status)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(6))
            {
                TD.WriteEtwEvent(6, eventTraceActivity, Uri, Status, payload.AppDomainFriendlyName);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Gets trace definition like: ByteStreamMessageEncoder started encoding the message.
        /// Event description ID=4802, Level=verbose, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void ByteStreamMessageEncodingStart(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(2))
            {
                TD.WriteEtwEvent(2, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Gets trace definition like: WAS connection timed out.
        /// Event description ID=4032, Level=Critical, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void WasConnectionTimedout(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(24))
            {
                TD.WriteEtwEvent(24, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Gets trace definition like: Pipe transport listener listening stop.
        /// Event description ID=4029, Level=Verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void PipeTransportListenerListeningStop(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(21))
            {
                TD.WriteEtwEvent(21, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Gets trace definition like: Was closing all listener channel instances completed.
        /// Event description ID=4023, Level=Informational, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void WasCloseAllListenerChannelInstancesCompleted(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(15))
            {
                TD.WriteEtwEvent(15, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
        /// <summary>
        /// Gets trace definition like: ServiceHost started: '{0}'.
        /// Event description ID=213, Level=LogAlways, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="ServiceTypeName">Parameter 0 for event: ServiceHost started: '{0}'.</param>
        /// <param name="reference">Reference (e.g. service reference) to be added to trace</param>
        internal static void ServiceHostStarted(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string ServiceTypeName, string reference)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(12))
            {
                TD.WriteEtwEvent(12, eventTraceActivity, ServiceTypeName, reference, payload.AppDomainFriendlyName);
            }
        }
        /// <summary>
        /// Gets trace definition like: Received request with virtual path '{1}' from the AppDomain '{0}'.
        /// Event description ID=513, Level=informational, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="AppDomainFriendlyName">Parameter 0 for event: Received request with virtual path '{1}' from the AppDomain '{0}'.</param>
        /// <param name="VirtualPath">Parameter 1 for event: Received request with virtual path '{1}' from the AppDomain '{0}'.</param>
        /// <param name="relatedActivityId">The related event activity Id</param>
        internal static void WebHostRequestStart(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string AppDomainFriendlyName, string VirtualPath, System.Guid relatedActivityId)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(8))
            {
                TD.WriteEtwTransferEvent(8, eventTraceActivity, relatedActivityId, AppDomainFriendlyName, VirtualPath, payload.AppDomainFriendlyName);
            }
        }
        /// <summary>
        /// Gets trace definition like: Begin CreateServiceHost
        /// Event description ID=505, Level=informational, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void CreateServiceHostStart(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(4))
            {
                TD.WriteEtwEvent(4, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Gets trace definition like: Retrieval of issuer name from tokenId:{0} failed.
        /// Event description ID=5406, Level=Error, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="tokenID">Parameter 0 for event: Retrieval of issuer name from tokenId:{0} failed.</param>
        internal static void GetIssuerNameFailure(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string tokenID)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null, true);

            if (TD.IsEtwEventEnabled(0))
            {
                TD.WriteEtwEvent(0, eventTraceActivity, tokenID, payload.HostReference, payload.AppDomainFriendlyName);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Gets trace definition like: SecurityToken (type '{0}' and id '{1}') validation succeeded.
        /// Event description ID=5403, Level=Verbose, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="tokenType">Parameter 0 for event: SecurityToken (type '{0}' and id '{1}') validation succeeded.</param>
        /// <param name="tokenID">Parameter 1 for event: SecurityToken (type '{0}' and id '{1}') validation succeeded.</param>
        internal static void TokenValidationSuccess(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string tokenType, string tokenID)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null, true);

            if (TD.IsEtwEventEnabled(4))
            {
                TD.WriteEtwEvent(4, eventTraceActivity, tokenType, tokenID, payload.HostReference, payload.AppDomainFriendlyName);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Gets trace definition like: Error Code:{0}
        /// Event description ID=4025, Level=Error, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="hresult">Parameter 0 for event: Error Code:{0}</param>
        internal static void OpenListenerChannelInstanceFailed(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string hresult)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(17))
            {
                TD.WriteEtwEvent(17, eventTraceActivity, hresult, payload.AppDomainFriendlyName);
            }
        }
        /// <summary>
        /// Gets trace definition like: End compilation
        /// Event description ID=502, Level=informational, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void CompilationStop(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(1))
            {
                TD.WriteEtwEvent(1, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Gets trace definition like: Session dispatch failed.
        /// Event description ID=4031, Level=Error, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void DispatchSessionFailed(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(23))
            {
                TD.WriteEtwEvent(23, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #22
0
        /// <summary>
        /// Gets trace definition like: Session dispatch for '{0}' failed since pending session queue is full with '{1}' pending items.
        /// Event description ID=4010, Level=Warning, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="Uri">Parameter 0 for event: Session dispatch for '{0}' failed since pending session queue is full with '{1}' pending items.</param>
        /// <param name="count">Parameter 1 for event: Session dispatch for '{0}' failed since pending session queue is full with '{1}' pending items.</param>
        internal static void PendingSessionQueueFull(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string Uri, int count)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(4))
            {
                TD.WriteEtwEvent(4, eventTraceActivity, Uri, count, payload.AppDomainFriendlyName);
            }
        }
Beispiel #23
0
        /// <summary>
        /// Gets trace definition like: Transport listener session received with via '{0}'
        /// Event description ID=4001, Level=Verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="via">Parameter 0 for event: Transport listener session received with via '{0}'</param>
        internal static void TransportListenerSessionsReceived(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string via)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(0))
            {
                TD.WriteEtwEvent(0, eventTraceActivity, via, payload.AppDomainFriendlyName);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Gets trace definition like: Message queue register start.
        /// Event description ID=4011, Level=Verbose, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void MessageQueueRegisterStart(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(5))
            {
                TD.WriteEtwEvent(5, eventTraceActivity, payload.AppDomainFriendlyName);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Gets trace definition like: Error Code:{0}
        /// Event description ID=4022, Level=Error, Channel=Analytic
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="hresult">Parameter 0 for event: Error Code:{0}</param>
        internal static void WebhostUnregisterProtocolFailed(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string hresult)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(14))
            {
                TD.WriteEtwEvent(14, eventTraceActivity, hresult, payload.AppDomainFriendlyName);
            }
        }
        /// <summary>
        /// Gets trace definition like: Message received by workflow
        /// Event description ID=1449, Level=Informational, Channel=Debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="relatedActivityId">The related event activity Id</param>
        internal static void WfMessageReceived(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, System.Guid relatedActivityId)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(17))
            {
                TD.WriteEtwTransferEvent(17, eventTraceActivity, relatedActivityId, payload.AppDomainFriendlyName);
            }
        }
 /// <summary>
 /// Gets trace definition like: A {0} message with messageId='{1}' was dropped by the DiscoveryClient because the corresponding {2} operation was completed.
 /// Event description ID=4804, Level=Informational, Channel=debug
 /// </summary>
 /// <param name="eventTraceActivity">The event trace activity</param>
 /// <param name="discoveryMessageName">Parameter 0 for event: A {0} message with messageId='{1}' was dropped by the DiscoveryClient because the corresponding {2} operation was completed.</param>
 /// <param name="messageId">Parameter 1 for event: A {0} message with messageId='{1}' was dropped by the DiscoveryClient because the corresponding {2} operation was completed.</param>
 /// <param name="discoveryOperationName">Parameter 2 for event: A {0} message with messageId='{1}' was dropped by the DiscoveryClient because the corresponding {2} operation was completed.</param>
 internal static void DiscoveryMessageReceivedAfterOperationCompleted(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string discoveryMessageName, string messageId, string discoveryOperationName)
 {
     TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);
     if (TD.IsEtwEventEnabled(3))
     {
         TD.WriteEtwEvent(3, eventTraceActivity, discoveryMessageName, messageId, discoveryOperationName, payload.AppDomainFriendlyName);
     }
     if (FxTrace.ShouldTraceInformationToTraceSource)
     {
         string description = string.Format(Culture, ResourceManager.GetString("DiscoveryMessageReceivedAfterOperationCompleted", Culture), discoveryMessageName, messageId, discoveryOperationName);
         TD.WriteTraceSource(3, description, payload);
     }
 }
 public SqlCommandAsyncResult(SqlCommand sqlCommand, string connectionString, EventTraceActivity eventTraceActivity, DependentTransaction dependentTransaction,
     TimeSpan timeout, int retryCount, int maximumRetries, AsyncCallback callback, object state)
     : base(callback, state)
 {
     long openTimeout = Math.Min(timeout.Ticks, SqlCommandAsyncResult.MaximumOpenTimeout.Ticks);
     this.sqlCommand = sqlCommand;
     this.connectionString = connectionString;
     this.eventTraceActivity = eventTraceActivity;
     this.dependentTransaction = dependentTransaction;
     this.timeoutHelper = new TimeoutHelper(TimeSpan.FromTicks(openTimeout));
     this.retryCount = retryCount;
     this.maximumRetries = maximumRetries;
 }
 /// <summary>
 /// Gets trace definition like: A {0} message with messageId='{1}' was dropped because it was a duplicate.
 /// Event description ID=4813, Level=Warning, Channel=debug
 /// </summary>
 /// <param name="eventTraceActivity">The event trace activity</param>
 /// <param name="messageType">Parameter 0 for event: A {0} message with messageId='{1}' was dropped because it was a duplicate.</param>
 /// <param name="messageId">Parameter 1 for event: A {0} message with messageId='{1}' was dropped because it was a duplicate.</param>
 internal static void DuplicateDiscoveryMessage(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string messageType, string messageId)
 {
     TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);
     if (TD.IsEtwEventEnabled(12))
     {
         TD.WriteEtwEvent(12, eventTraceActivity, messageType, messageId, payload.AppDomainFriendlyName);
     }
     if (FxTrace.ShouldTraceWarningToTraceSource)
     {
         string description = string.Format(Culture, ResourceManager.GetString("DuplicateDiscoveryMessage", Culture), messageType, messageId);
         TD.WriteTraceSource(12, description, payload);
     }
 }
        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;
        }
        /// <summary>
        /// Gets trace definition like: Timeout trying to open a SQL connection. The operation did not complete within the allotted timeout of {0}. The time allotted to this operation may have been a portion of a longer timeout.
        /// Event description ID=4209, Level=Error, Channel=debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="param0">Parameter 0 for event: Timeout trying to open a SQL connection. The operation did not complete within the allotted timeout of {0}. The time allotted to this operation may have been a portion of a longer timeout.</param>
        internal static void TimeoutOpeningSqlConnection(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string param0)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(7))
            {
                TD.WriteEtwEvent(7, eventTraceActivity, param0, payload.AppDomainFriendlyName);
            }
            if (FxTrace.ShouldTraceErrorToTraceSource)
            {
                string description = string.Format(Culture, ResourceManager.GetString("TimeoutOpeningSqlConnection", Culture), param0);
                TD.WriteTraceSource(7, description, payload);
            }
        }
        /// <summary>
        /// Gets trace definition like: Retrying a SQL command due to SQL error number {0}.
        /// Event description ID=4208, Level=Informational, Channel=debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="param0">Parameter 0 for event: Retrying a SQL command due to SQL error number {0}.</param>
        internal static void RetryingSqlCommandDueToSqlError(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string param0)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(6))
            {
                TD.WriteEtwEvent(6, eventTraceActivity, param0, payload.AppDomainFriendlyName);
            }
            if (FxTrace.ShouldTraceInformationToTraceSource)
            {
                string description = string.Format(Culture, ResourceManager.GetString("RetryingSqlCommandDueToSqlError", Culture), param0);
                TD.WriteTraceSource(6, description, payload);
            }
        }
        /// <summary>
        /// Gets trace definition like: Giving up retrying a SQL command as the maximum number of retries have been performed.
        /// Event description ID=4207, Level=Informational, Channel=debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        internal static void MaximumRetriesExceededForSqlCommand(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(5))
            {
                TD.WriteEtwEvent(5, eventTraceActivity, payload.AppDomainFriendlyName);
            }
            if (FxTrace.ShouldTraceInformationToTraceSource)
            {
                string description = string.Format(Culture, ResourceManager.GetString("MaximumRetriesExceededForSqlCommand", Culture));
                TD.WriteTraceSource(5, description, payload);
            }
        }
        /// <summary>
        /// Gets trace definition like: Command failed: {0}
        /// Event description ID=4205, Level=Error, Channel=debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="param0">Parameter 0 for event: Command failed: {0}</param>
        /// <param name="exception">Exception associated with the event</param>
        internal static void FoundProcessingError(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string param0, System.Exception exception)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, exception);

            if (TD.IsEtwEventEnabled(3))
            {
                TD.WriteEtwEvent(3, eventTraceActivity, param0, payload.SerializedException, payload.AppDomainFriendlyName);
            }
            if (FxTrace.ShouldTraceErrorToTraceSource)
            {
                string description = string.Format(Culture, ResourceManager.GetString("FoundProcessingError", Culture), param0);
                TD.WriteTraceSource(3, description, payload);
            }
        }
        /// <summary>
        /// Gets trace definition like: Queuing SQL retry with delay {0} milliseconds.
        /// Event description ID=4211, Level=Warning, Channel=debug
        /// </summary>
        /// <param name="eventTraceActivity">The event trace activity</param>
        /// <param name="param0">Parameter 0 for event: Queuing SQL retry with delay {0} milliseconds.</param>
        internal static void QueuingSqlRetry(System.Runtime.Diagnostics.EventTraceActivity eventTraceActivity, string param0)
        {
            TracePayload payload = FxTrace.Trace.GetSerializedPayload(null, null, null);

            if (TD.IsEtwEventEnabled(10))
            {
                TD.WriteEtwEvent(10, eventTraceActivity, param0, payload.AppDomainFriendlyName);
            }
            if (FxTrace.ShouldTraceWarningToTraceSource)
            {
                string description = string.Format(Culture, ResourceManager.GetString("QueuingSqlRetry", Culture), param0);
                TD.WriteTraceSource(10, description, payload);
            }
        }
Beispiel #36
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store = store;
            Owner = owner;
            Id = instanceId;
            View = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
Beispiel #37
0
 internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
 {
     this.Action = action;
     this.Activity = null;
     _eventTraceActivity = null;
     this.Channel = channel;
     this.Correlation = EmptyArray<object>.Allocate(operation.Parent.CorrelationCount);
     this.InputParameters = inputs;
     this.Operation = operation;
     this.OutputParameters = null;
     this.Request = null;
     this.Reply = null;
     this.ActivityId = Guid.Empty;
     this.ReturnValue = null;
     this.MessageVersion = channel.MessageVersion;
     this.TimeoutHelper = new TimeoutHelper(timeout);
 }
        internal InstancePersistenceContext(InstanceHandle handle, Transaction transaction)
            : this(handle)
        {
            Fx.Assert(transaction != null, "Null Transaction passed to InstancePersistenceContext.");

            // Let's take our own clone of the transaction. We need to do this because we might need to
            // create a TransactionScope using the transaction and in cases where we are dealing with a
            // transaction that is flowed into the workflow on a message, the DependentTransaction that the
            // dispatcher creates and sets to Transaction.Current may already be Completed by the time a
            // Save operation is done. And since TransactionScope creates a DependentTransaction, it won't
            // be able to.
            // We don't create another DependentClone because we are going to do a EnlistVolatile on the
            // transaction ourselves.
            this.transaction = transaction.Clone();
            IsHostTransaction = true;
            this.eventTraceActivity = handle.EventTraceActivity;
        }
        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;
        }
Beispiel #40
0
		internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, Guid value1, string value2, string value3)
		{
			string str = value2;
			string empty = str;
			if (str == null)
			{
				empty = string.Empty;
			}
			value2 = empty;
			string str1 = value3;
			string empty1 = str1;
			if (str1 == null)
			{
				empty1 = string.Empty;
			}
			value3 = empty1;
			fixed (string str2 = value2)
			{
				string* strPointers = &str2;
				char* offsetToStringData = (char*)(&str2);
				if (&str2 != null)
				{
					offsetToStringData = (char*)(strPointers + RuntimeHelpers.OffsetToStringData);
				}
				char* chrPointer = offsetToStringData;
				fixed (string str3 = value3)
				{
					string* strPointers1 = &str3;
					char* offsetToStringData1 = (char*)(&str3);
					if (&str3 != null)
					{
						offsetToStringData1 = (char*)(strPointers1 + RuntimeHelpers.OffsetToStringData);
					}
					byte* length = (byte*)sizeof(UnsafeNativeMethods.EventData) * 3;
					(*((UnsafeNativeMethods.EventData*)length)).DataPointer = (ulong)(&value1);
					(*((UnsafeNativeMethods.EventData*)length)).Size = sizeof(Guid);
					((UnsafeNativeMethods.EventData*)length + sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)chrPointer;
					((UnsafeNativeMethods.EventData*)length + sizeof(UnsafeNativeMethods.EventData)).Size = (value2.Length + 1) * 2;
					((UnsafeNativeMethods.EventData*)length + 2 * sizeof(UnsafeNativeMethods.EventData)).DataPointer = (ulong)offsetToStringData1;
					((UnsafeNativeMethods.EventData*)length + 2 * sizeof(UnsafeNativeMethods.EventData)).Size = (value3.Length + 1) * 2;
					bool flag = base.WriteEvent(ref eventDescriptor, eventTraceActivity, 3, (IntPtr)length);
					return flag;
				}
			}
		}
        protected TransportOutputChannel(ChannelManagerBase channelManager, EndpointAddress to, Uri via, bool manualAddressing, MessageVersion messageVersion)
            : base(channelManager)
        {
            _manualAddressing = manualAddressing;
            _messageVersion = messageVersion;
            _to = to;
            _via = via;

            if (!manualAddressing && to != null)
            {
                Uri toUri;
                if (to.IsAnonymous)
                {
                    toUri = _messageVersion.Addressing.AnonymousUri;
                }
                else if (to.IsNone)
                {
                    toUri = _messageVersion.Addressing.NoneUri;
                }
                else
                {
                    toUri = to.Uri;
                }

                if (toUri != null)
                {
                    XmlDictionaryString dictionaryTo = new ToDictionary(toUri.AbsoluteUri).To;
                    _toHeader = ToHeader.Create(toUri, dictionaryTo, messageVersion.Addressing);
                }

                _anyHeadersToAdd = to.Headers.Count > 0;
            }

            if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                _channelEventTraceActivity = EventTraceActivity.GetFromThreadOrCreate();
            }
        }
        public bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, params object[] eventPayload)
        {
            uint status = 0;

            if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                int argCount = 0;

                if (eventTraceActivity != null)
                {
                    SetActivityId(ref eventTraceActivity.ActivityId);
                }

                unsafe
                {
                    if ((eventPayload == null)
                        || (eventPayload.Length == 0)
                        || (eventPayload.Length == 1))
                    {
                        string dataString = null;
                        UnsafeNativeMethods.EventData userData;

                        byte* dataBuffer = stackalloc byte[basicTypeAllocationBufferSize]; // Assume a max of 16 chars for non-string argument

                        userData.Size = 0;
                        if ((eventPayload != null) && (eventPayload.Length != 0))
                        {
                            //
                            // Figure out the type and fill the data descriptor
                            //
                            dataString = EncodeObject(ref eventPayload[0], &userData, dataBuffer);
                            argCount = 1;
                        }

                        if (userData.Size > traceEventMaximumSize)
                        {
                            //
                            // Maximum size of the event payload plus header is 64k
                            //
                            errorCode = WriteEventErrorCode.EventTooBig;
                            return false;
                        }

                        if (dataString != null)
                        {
                            fixed (char* pdata = dataString)
                            {
                                userData.DataPointer = (ulong)pdata;
                                status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)argCount, &userData);
                            }
                        }
                        else
                        {
                            if (argCount == 0)
                            {
                                status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 0, null);
                            }
                            else
                            {
                                status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)argCount, &userData);
                            }

                        }
                    }
                    else
                    {

                        argCount = eventPayload.Length;

                        if (argCount > etwMaxNumberArguments)
                        {
                            //
                            //too many arguments to log
                            //
                            throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload",
                                InternalSR.EtwMaxNumberArgumentsExceeded(etwMaxNumberArguments)));
                        }

                        uint totalEventSize = 0;
                        int index;
                        int stringIndex = 0;
                        int[] stringPosition = new int[etwAPIMaxStringCount];
                        string[] dataString = new string[etwAPIMaxStringCount];
                        UnsafeNativeMethods.EventData* userData = stackalloc UnsafeNativeMethods.EventData[argCount];
                        UnsafeNativeMethods.EventData* userDataPtr = (UnsafeNativeMethods.EventData*)userData;
                        byte* dataBuffer = stackalloc byte[basicTypeAllocationBufferSize * argCount]; // Assume 16 chars for non-string argument
                        byte* currentBuffer = dataBuffer;

                        //
                        // The loop below goes through all the arguments and fills in the data 
                        // descriptors. For strings save the location in the dataString array.
                        // Caculates the total size of the event by adding the data descriptor
                        // size value set in EncodeObjec method.
                        //
                        for (index = 0; index < eventPayload.Length; index++)
                        {
                            if (eventPayload[index] != null)
                            {
                                string isString;
                                isString = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer);
                                currentBuffer += basicTypeAllocationBufferSize;
                                totalEventSize += userDataPtr->Size;
                                userDataPtr++;
                                if (isString != null)
                                {
                                    if (stringIndex < etwAPIMaxStringCount)
                                    {
                                        dataString[stringIndex] = isString;
                                        stringPosition[stringIndex] = index;
                                        stringIndex++;
                                    }
                                    else
                                    {
                                        throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload",
                                            InternalSR.EtwAPIMaxStringCountExceeded(etwAPIMaxStringCount))); 
                                    }
                                }
                            }
                        }

                        if (totalEventSize > traceEventMaximumSize)
                        {
                            errorCode = WriteEventErrorCode.EventTooBig;
                            return false;
                        }

                        //
                        // now fix any string arguments and set the pointer on the data descriptor 
                        //
                        fixed (char* v0 = dataString[0], v1 = dataString[1], v2 = dataString[2], v3 = dataString[3],
                                v4 = dataString[4], v5 = dataString[5], v6 = dataString[6], v7 = dataString[7])
                        {
                            userDataPtr = (UnsafeNativeMethods.EventData*)userData;
                            if (dataString[0] != null)
                            {
                                userDataPtr[stringPosition[0]].DataPointer = (ulong)v0;
                            }
                            if (dataString[1] != null)
                            {
                                userDataPtr[stringPosition[1]].DataPointer = (ulong)v1;
                            }
                            if (dataString[2] != null)
                            {
                                userDataPtr[stringPosition[2]].DataPointer = (ulong)v2;
                            }
                            if (dataString[3] != null)
                            {
                                userDataPtr[stringPosition[3]].DataPointer = (ulong)v3;
                            }
                            if (dataString[4] != null)
                            {
                                userDataPtr[stringPosition[4]].DataPointer = (ulong)v4;
                            }
                            if (dataString[5] != null)
                            {
                                userDataPtr[stringPosition[5]].DataPointer = (ulong)v5;
                            }
                            if (dataString[6] != null)
                            {
                                userDataPtr[stringPosition[6]].DataPointer = (ulong)v6;
                            }
                            if (dataString[7] != null)
                            {
                                userDataPtr[stringPosition[7]].DataPointer = (ulong)v7;
                            }

                            status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)argCount, userData);
                        }

                    }
                }
            }

            if (status != 0)
            {
                SetLastError((int)status);
                return false;
            }

            return true;
        }
        public bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, string data)
        {
            uint status = 0;
            //check all strings for null
            data = (data ?? string.Empty);

            if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                if (data.Length > traceEventMaximumStringSize)
                {
                    errorCode = WriteEventErrorCode.EventTooBig;
                    return false;
                }

                if (eventTraceActivity != null)
                {
                    SetActivityId(ref eventTraceActivity.ActivityId);
                }

                UnsafeNativeMethods.EventData userData;

                userData.Size = (uint)((data.Length + 1) * 2);
                userData.Reserved = 0;

                unsafe
                {
                    fixed (char* pdata = data)
                    {
                        userData.DataPointer = (ulong)pdata;
                        status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, 1, &userData);
                    }
                }
            }

            if (status != 0)
            {
                SetLastError((int)status);
                return false;
            }
            return true;
        }
        public bool WriteMessageEvent(EventTraceActivity eventTraceActivity, string eventMessage, byte eventLevel, long eventKeywords)
        {
            int status = 0;

            if (eventMessage == null)
            {
                throw Fx.Exception.AsError(new ArgumentNullException("eventMessage"));
            }

            if (eventTraceActivity != null)
            {
                SetActivityId(ref eventTraceActivity.ActivityId); 
            }

            if (IsEnabled(eventLevel, eventKeywords))
            {
                if (eventMessage.Length > traceEventMaximumStringSize)
                {
                    errorCode = WriteEventErrorCode.EventTooBig;
                    return false;
                }
                unsafe
                {
                    fixed (char* pdata = eventMessage)
                    {
                        status = (int)UnsafeNativeMethods.EventWriteString(this.traceRegistrationHandle, eventLevel, eventKeywords, pdata);
                    }

                    if (status != 0)
                    {
                        SetLastError(status);
                        return false;
                    }
                }
            }
            return true;
        }
 public bool WriteMessageEvent(EventTraceActivity eventTraceActivity, string eventMessage)
 {
     return WriteMessageEvent(eventTraceActivity, eventMessage, 0, 0);
 }
        internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, string value1, string value2, string value3, string value4,
            string value5, string value6, string value7, string value8, string value9, string value10)
        {
            const int argumentCount = 10;
            bool status = true;

            //check all strings for null
            value1 = (value1 ?? string.Empty);
            value2 = (value2 ?? string.Empty);
            value3 = (value3 ?? string.Empty);
            value4 = (value4 ?? string.Empty);
            value5 = (value5 ?? string.Empty);
            value6 = (value6 ?? string.Empty);
            value7 = (value7 ?? string.Empty);
            value8 = (value8 ?? string.Empty);
            value9 = (value9 ?? string.Empty);
            value10 = (value10 ?? string.Empty);

            fixed (char* string1Bytes = value1, string2Bytes = value2, string3Bytes = value3, string4Bytes = value4, string5Bytes = value5, string6Bytes = value6,
            string7Bytes = value7, string8Bytes = value8, string9Bytes = value9, string10Bytes = value10)
            {
                byte* eventData = stackalloc byte[sizeof(UnsafeNativeMethods.EventData) * argumentCount];
                UnsafeNativeMethods.EventData* eventDataPtr = (UnsafeNativeMethods.EventData*)eventData;
                
                eventDataPtr[0].DataPointer = (ulong)string1Bytes;
                eventDataPtr[0].Size = (uint)(value1.Length + 1) * sizeof(char);
            
                eventDataPtr[1].DataPointer = (ulong)string2Bytes;
                eventDataPtr[1].Size = (uint)(value2.Length + 1) * sizeof(char);
            
                eventDataPtr[2].DataPointer = (ulong)string3Bytes;
                eventDataPtr[2].Size = (uint)(value3.Length + 1) * sizeof(char);
            
                eventDataPtr[3].DataPointer = (ulong)string4Bytes;
                eventDataPtr[3].Size = (uint)(value4.Length + 1) * sizeof(char);
            
                eventDataPtr[4].DataPointer = (ulong)string5Bytes;
                eventDataPtr[4].Size = (uint)(value5.Length + 1) * sizeof(char);
            
                eventDataPtr[5].DataPointer = (ulong)string6Bytes;
                eventDataPtr[5].Size = (uint)(value6.Length + 1) * sizeof(char);
            
                eventDataPtr[6].DataPointer = (ulong)string7Bytes;
                eventDataPtr[6].Size = (uint)(value7.Length + 1) * sizeof(char);
            
                eventDataPtr[7].DataPointer = (ulong)string8Bytes;
                eventDataPtr[7].Size = (uint)(value8.Length + 1) * sizeof(char);
            
                eventDataPtr[8].DataPointer = (ulong)string9Bytes;
                eventDataPtr[8].Size = (uint)(value9.Length + 1) * sizeof(char);
            
                eventDataPtr[9].DataPointer = (ulong)string10Bytes;
                eventDataPtr[9].Size = (uint)(value10.Length + 1) * sizeof(char);                

                status = WriteEvent(ref eventDescriptor, eventTraceActivity, argumentCount, (IntPtr)(eventData));
            }

            return status;
        }
 internal static void SetOnThread(EventTraceActivity eventTraceActivity)
 {
     if (eventTraceActivity != null)
     {
     }
 }
Beispiel #48
0
        private static void EnsureEventTraceActivity(Message message)
        {
            //We need to send this only if there is no message id. 
            if (message.Headers.MessageId == null)
            {
                EventTraceActivity eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                if (eventTraceActivity == null)
                {
                    //Whoops no activity on the message yet.                         
                    eventTraceActivity = new EventTraceActivity();
                    EventTraceActivityHelper.TryAttachActivity(message, eventTraceActivity);
                }

                HttpRequestMessageProperty httpProperties;
                if (!message.Properties.TryGetValue<HttpRequestMessageProperty>(HttpRequestMessageProperty.Name, out httpProperties))
                {
                    httpProperties = new HttpRequestMessageProperty();
                    message.Properties.Add(HttpRequestMessageProperty.Name, httpProperties);
                }
                httpProperties.Headers.Add(EventTraceActivity.Name, Convert.ToBase64String(eventTraceActivity.ActivityId.ToByteArray()));
            }
        }
        void TraceHttpMessageReceived(Message message)
        {
            if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                bool attached = false;
                Guid relatedId = this.eventTraceActivity != null ? this.eventTraceActivity.ActivityId : Guid.Empty;
                HttpRequestMessageProperty httpProperty;

                // Encoder will always add an activity. We need to remove this and read it
                // from the web headers for http since correlation might be propogated.
                if (message.Headers.MessageId == null &&
                    message.Properties.TryGetValue<HttpRequestMessageProperty>(HttpRequestMessageProperty.Name, out httpProperty))
                {
                    try
                    {
                        string e2eId = httpProperty.Headers[EventTraceActivity.Name];
                        if (!String.IsNullOrEmpty(e2eId))
                        {
                            byte[] data = Convert.FromBase64String(e2eId);
                            if (data != null && data.Length == 16)
                            {
                                Guid id = new Guid(data);
                                this.eventTraceActivity = new EventTraceActivity(id, true);
                                message.Properties[EventTraceActivity.Name] = this.eventTraceActivity;
                                attached = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                        {
                            throw;
                        }
                    }
                }

                if (!attached)
                {
                    this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message, true);
                }

                if (TD.MessageReceivedByTransportIsEnabled())
                {
                    TD.MessageReceivedByTransport(
                        this.eventTraceActivity,
                        this.listener != null && this.listener.Uri != null ? this.listener.Uri.AbsoluteUri : string.Empty,
                        relatedId);
                }
            }
        }
        protected bool WriteTransferEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, Guid relatedActivityId, int dataCount, IntPtr data)
        {
            // ActivityId is required when writing transfer event
            if (eventTraceActivity == null)
            {
                throw Fx.Exception.ArgumentNull("eventTraceActivity");
            }

            uint status = 0;
            unsafe
            {
                status = UnsafeNativeMethods.EventWriteTransfer(this.traceRegistrationHandle,
                                                ref eventDescriptor,
                                                ref eventTraceActivity.ActivityId,
                                                ref relatedActivityId,
                                                (uint)dataCount,
                                                (UnsafeNativeMethods.EventData*)data);
            }

            if (status != 0)
            {
                SetLastError((int)status);
                return false;
            }
            return true;
        }
 public ListenerHttpContext(HttpChannelListener listener,
     HttpListenerContext listenerContext, EventTraceActivity eventTraceActivity)
     : base(listener, null, eventTraceActivity)
 {
     this.listenerContext = listenerContext;
 }
        internal protected bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, int dataCount, IntPtr data)
        {
            uint status = 0;

            if (eventTraceActivity != null)
            {
                SetActivityId(ref eventTraceActivity.ActivityId);
            }

            unsafe
            {
                status = UnsafeNativeMethods.EventWrite(this.traceRegistrationHandle, ref eventDescriptor, (uint)dataCount, (UnsafeNativeMethods.EventData*)data);
            }
            if (status != 0)
            {
                SetLastError((int)status);
                return false;
            }
            return true;
        }
 internal static HttpRequestContext CreateContext(HttpChannelListener listener, HttpListenerContext listenerContext, EventTraceActivity eventTraceActivity)
 {
     return new ListenerHttpContext(listener, listenerContext, eventTraceActivity);
 }
 internal static void TraceIdentityVerificationSuccess(EventTraceActivity eventTraceActivity, EndpointIdentity identity, Claim claim, Type identityVerifier)
 {
 }
        internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, long value1, long value2, long value3)
        {
            const int argumentCount = 3;
            bool status = true;

            {
                byte* eventData = stackalloc byte[sizeof(UnsafeNativeMethods.EventData) * argumentCount];
                UnsafeNativeMethods.EventData* eventDataPtr = (UnsafeNativeMethods.EventData*)eventData;

                eventDataPtr[0].DataPointer = (UInt64)(&value1);
                eventDataPtr[0].Size = (uint)(sizeof(long));

                eventDataPtr[1].DataPointer = (UInt64)(&value2);
                eventDataPtr[1].Size = (uint)(sizeof(long));

                eventDataPtr[2].DataPointer = (UInt64)(&value3);
                eventDataPtr[2].Size = (uint)(sizeof(long));

                status = WriteEvent(ref eventDescriptor, eventTraceActivity, argumentCount, (IntPtr)(eventData));
            }

            return status;
        }
        internal unsafe bool WriteEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, Guid value1, long value2, long value3, string value4,
            string value5, string value6, string value7, string value8, string value9, string value10, string value11, string value12,
            bool value13, string value14, string value15, string value16, string value17)
        {
            const int argumentCount = 17;
            bool status = true;

            //check all strings for null           
            value4 = (value4 ?? string.Empty);
            value5 = (value5 ?? string.Empty);
            value6 = (value6 ?? string.Empty);
            value7 = (value7 ?? string.Empty);
            value8 = (value8 ?? string.Empty);
            value9 = (value9 ?? string.Empty);
            value10 = (value10 ?? string.Empty);
            value11 = (value11 ?? string.Empty);
            value12 = (value12 ?? string.Empty);
            //value13 is not string            
            value14 = (value14 ?? string.Empty);
            value15 = (value15 ?? string.Empty);
            value16 = (value16 ?? string.Empty);
            value17 = (value17 ?? string.Empty);

            fixed (char* string1Bytes = value4, string2Bytes = value5, string3Bytes = value6, string4Bytes = value7, string5Bytes = value8, string6Bytes = value9,
            string7Bytes = value10, string8Bytes = value11, string9Bytes = value12, string10Bytes = value14, string11Bytes = value15, 
            string12Bytes = value16, string13Bytes = value17)
            {
                byte* eventData = stackalloc byte[sizeof(UnsafeNativeMethods.EventData) * argumentCount];
                UnsafeNativeMethods.EventData* eventDataPtr = (UnsafeNativeMethods.EventData*)eventData;                

                eventDataPtr[0].DataPointer = (ulong)(&value1);
                eventDataPtr[0].Size = (uint)(sizeof(Guid));

                eventDataPtr[1].DataPointer = (ulong)(&value2);
                eventDataPtr[1].Size = (uint)(sizeof(long));

                eventDataPtr[2].DataPointer = (ulong)(&value3);
                eventDataPtr[2].Size = (uint)(sizeof(long));
               
                eventDataPtr[3].DataPointer = (ulong)string1Bytes;
                eventDataPtr[3].Size = (uint)(value4.Length + 1) * sizeof(char);
           
                eventDataPtr[4].DataPointer = (ulong)string2Bytes;
                eventDataPtr[4].Size = (uint)(value5.Length + 1) * sizeof(char);
           
                eventDataPtr[5].DataPointer = (ulong)string3Bytes;
                eventDataPtr[5].Size = (uint)(value6.Length + 1) * sizeof(char);
           
                eventDataPtr[6].DataPointer = (ulong)string4Bytes;
                eventDataPtr[6].Size = (uint)(value7.Length + 1) * sizeof(char);
           
                eventDataPtr[7].DataPointer = (ulong)string5Bytes;
                eventDataPtr[7].Size = (uint)(value8.Length + 1) * sizeof(char);
           
                eventDataPtr[8].DataPointer = (ulong)string6Bytes;
                eventDataPtr[8].Size = (uint)(value9.Length + 1) * sizeof(char);
            
                eventDataPtr[9].DataPointer = (ulong)string7Bytes;
                eventDataPtr[9].Size = (uint)(value10.Length + 1) * sizeof(char);
            
                eventDataPtr[10].DataPointer = (ulong)string8Bytes;
                eventDataPtr[10].Size = (uint)(value11.Length + 1) * sizeof(char);
           
                eventDataPtr[11].DataPointer = (ulong)string9Bytes;
                eventDataPtr[11].Size = (uint)(value12.Length + 1) * sizeof(char);
               
                eventDataPtr[12].DataPointer = (ulong)(&value13);
                eventDataPtr[12].Size = (uint)(sizeof(bool));
               
                eventDataPtr[13].DataPointer = (ulong)string10Bytes;
                eventDataPtr[13].Size = (uint)(value14.Length + 1) * sizeof(char);
           
                eventDataPtr[14].DataPointer = (ulong)string11Bytes;
                eventDataPtr[14].Size = (uint)(value15.Length + 1) * sizeof(char);
           
                eventDataPtr[15].DataPointer = (ulong)string12Bytes;
                eventDataPtr[15].Size = (uint)(value16.Length + 1) * sizeof(char);
           
                eventDataPtr[16].DataPointer = (ulong)string13Bytes;
                eventDataPtr[16].Size = (uint)(value17.Length + 1) * sizeof(char);
               
                status = WriteEvent(ref eventDescriptor, eventTraceActivity, argumentCount, (IntPtr)(eventData));
            }

            return status;

        }
        public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, EventTraceActivity eventTraceActivity, Guid relatedActivityId, params object[] eventPayload)
        {
            // ActivityId is required when writing transfer event
            if (eventTraceActivity == null)
            {
                Fx.Assert(false, "eventTraceActivity should not be null for WriteTransferEvent");
                eventTraceActivity = EventTraceActivity.Empty;
            }

            uint status = 0;
            if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                unsafe
                {
                    if ((eventPayload != null) && (eventPayload.Length != 0))
                    {
                        int argCount = eventPayload.Length;
                        if (argCount > etwMaxNumberArguments)
                        {
                            //
                            //too many arguments to log
                            //
                            throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload",
                                InternalSR.EtwMaxNumberArgumentsExceeded(etwMaxNumberArguments)));
                        }

                        uint totalEventSize = 0;
                        int index;
                        int stringIndex = 0;
                        int[] stringPosition = new int[etwAPIMaxStringCount]; //used to keep the position of strings in the eventPayload parameter
                        string[] dataString = new string[etwAPIMaxStringCount]; // string arrays from the eventPayload parameter
                        UnsafeNativeMethods.EventData* userData = stackalloc UnsafeNativeMethods.EventData[argCount]; // allocation for the data descriptors
                        UnsafeNativeMethods.EventData* userDataPtr = (UnsafeNativeMethods.EventData*)userData;
                        byte* dataBuffer = stackalloc byte[basicTypeAllocationBufferSize * argCount]; // 16 byte for unboxing non-string argument
                        byte* currentBuffer = dataBuffer;

                        //
                        // The loop below goes through all the arguments and fills in the data 
                        // descriptors. For strings save the location in the dataString array.
                        // Caculates the total size of the event by adding the data descriptor
                        // size value set in EncodeObjec method.
                        //
                        for (index = 0; index < eventPayload.Length; index++)
                        {
                            if (eventPayload[index] != null)
                            {
                                string isString;
                                isString = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer);
                                currentBuffer += basicTypeAllocationBufferSize;
                                totalEventSize += userDataPtr->Size;
                                userDataPtr++;
                                if (isString != null)
                                {
                                    if (stringIndex < etwAPIMaxStringCount)
                                    {
                                        dataString[stringIndex] = isString;
                                        stringPosition[stringIndex] = index;
                                        stringIndex++;
                                    }
                                    else
                                    {                                        
                                        throw Fx.Exception.AsError(new ArgumentOutOfRangeException("eventPayload",
                                            InternalSR.EtwAPIMaxStringCountExceeded(etwAPIMaxStringCount)));  
                                    }
                                }
                            }
                        }

                        if (totalEventSize > traceEventMaximumSize)
                        {
                            errorCode = WriteEventErrorCode.EventTooBig;
                            return false;
                        }

                        fixed (char* v0 = dataString[0], v1 = dataString[1], v2 = dataString[2], v3 = dataString[3],
                                v4 = dataString[4], v5 = dataString[5], v6 = dataString[6], v7 = dataString[7])
                        {
                            userDataPtr = (UnsafeNativeMethods.EventData*)userData;
                            if (dataString[0] != null)
                            {
                                userDataPtr[stringPosition[0]].DataPointer = (ulong)v0;
                            }
                            if (dataString[1] != null)
                            {
                                userDataPtr[stringPosition[1]].DataPointer = (ulong)v1;
                            }
                            if (dataString[2] != null)
                            {
                                userDataPtr[stringPosition[2]].DataPointer = (ulong)v2;
                            }
                            if (dataString[3] != null)
                            {
                                userDataPtr[stringPosition[3]].DataPointer = (ulong)v3;
                            }
                            if (dataString[4] != null)
                            {
                                userDataPtr[stringPosition[4]].DataPointer = (ulong)v4;
                            }
                            if (dataString[5] != null)
                            {
                                userDataPtr[stringPosition[5]].DataPointer = (ulong)v5;
                            }
                            if (dataString[6] != null)
                            {
                                userDataPtr[stringPosition[6]].DataPointer = (ulong)v6;
                            }
                            if (dataString[7] != null)
                            {
                                userDataPtr[stringPosition[7]].DataPointer = (ulong)v7;
                            }

                            status = UnsafeNativeMethods.EventWriteTransfer(this.traceRegistrationHandle, ref eventDescriptor, ref eventTraceActivity.ActivityId, ref relatedActivityId, (uint)argCount, userData);
                        }
                    }
                    else
                    {
                        status = UnsafeNativeMethods.EventWriteTransfer(this.traceRegistrationHandle, ref eventDescriptor, ref eventTraceActivity.ActivityId, ref relatedActivityId, 0, null);
                    }
                }
            }

            if (status != 0)
            {
                SetLastError((int)status);
                return false;
            }

            return true;
        }
Beispiel #58
0
        protected HttpOutput(IHttpTransportFactorySettings settings, Message message, bool isRequest, bool supportsConcurrentIO)
        {
            this.settings = settings;
            this.message = message;
            this.isRequest = isRequest;
            this.bufferManager = settings.BufferManager;
            this.messageEncoder = settings.MessageEncoderFactory.Encoder;
            ICompressedMessageEncoder compressedMessageEncoder = this.messageEncoder as ICompressedMessageEncoder;
            this.canSendCompressedResponses = compressedMessageEncoder != null && compressedMessageEncoder.CompressionEnabled;
            if (isRequest)
            {
                this.streamed = TransferModeHelper.IsRequestStreamed(settings.TransferMode);
            }
            else
            {
                this.streamed = TransferModeHelper.IsResponseStreamed(settings.TransferMode);
            }
            this.supportsConcurrentIO = supportsConcurrentIO;

            if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
            }
        }
        internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation,
            ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread,
            OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity)
        {
            Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null");
            Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null");

            this.Activity = null;
            this.EventTraceActivity = eventTraceActivity;            
            this.AsyncResult = null;
            this.CanSendReply = true;
            this.Channel = channel;
            this.channelHandler = channelHandler;
            this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount);
            this.CorrelationCallback = null;
            this.DidDeserializeRequestBody = false;
            this.TransactionMessageProperty = null;
            this.TransactedBatchContext = null;
            this.Error = null;
            this.ErrorProcessor = null;
            this.FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction);
            this.HasSecurityContext = false;
            this.Host = host;
            this.Instance = null;
            this.MessageRpcOwnsInstanceContextThrottle = false;
            this.NextProcessor = null;
            this.NotUnderstoodHeaders = null;
            this.Operation = operation;
            this.OperationContext = operationContext;
            this.paused = false;
            this.ParametersDisposed = false;
            this.ReceiveContext = null;
            this.Request = request;
            this.RequestContext = requestContext;
            this.RequestContextThrewOnReply = false;
            this.SuccessfullySendReply = false;
            this.RequestVersion = request.Version;
            this.Reply = null;
            this.ReplyTimeoutHelper = new TimeoutHelper();
            this.SecurityContext = null;
            this.InstanceContext = instanceContext;
            this.SuccessfullyBoundInstance = false;
            this.SuccessfullyIncrementedActivity = false;
            this.SuccessfullyLockedInstance = false;
            this.switchedThreads = !cleanThread;
            this.transaction = null;
            this.InputParameters = null;
            this.OutputParameters = null;
            this.ReturnParameter = null;
            this.isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(this.Channel.DispatchRuntime.InstanceContextProvider);
            this.invokeContinueGate = null;

            if (!operation.IsOneWay && !operation.Parent.ManualAddressing)
            {
                this.RequestID = request.Headers.MessageId;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request);
            }
            else
            {
                this.RequestID = null;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo();
            }

            this.HostingProperty = AspNetEnvironment.Current.GetHostingProperty(request, true);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                this.Activity = TraceUtility.ExtractActivity(this.Request);
            }

            if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity)
            {
                this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request);
            }
            else
            {
                this.ResponseActivityId = Guid.Empty;
            }

            this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler);

            if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                if (this.Request != null)
                {
                    this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true);
                }
            }
        }
 protected HttpRequestContext(HttpChannelListener listener, Message requestMessage, EventTraceActivity eventTraceActivity)
     : base(requestMessage, listener.InternalCloseTimeout, listener.InternalSendTimeout)
 {
     this.listener = listener;
     this.eventTraceActivity = eventTraceActivity;
 }