TraceTransfer() приватный Метод

private TraceTransfer ( int id, string message, Guid relatedActivityId ) : void
id int
message string
relatedActivityId Guid
Результат void
Пример #1
0
        /// <summary>
        /// Constructor used to initialize the class
        /// </summary>
        /// <param name="traceSource">The source that we are tracing through as part of this scope</param>
        /// <param name="activityName">The name of the activity that this scope represents</param>
        public TraceTransferScope(TraceSource traceSource, string activityName)
        {
            if (traceSource == null)
            {
                throw new ArgumentNullException("traceSource");
            }

            if (string.IsNullOrEmpty(activityName))
            {
                throw new ArgumentNullException("activityName");
            }

            _traceSource = traceSource;
            _oldActivityId = Trace.CorrelationManager.ActivityId;
            _activityName = activityName;

            _newActivityId = Guid.NewGuid();

            if (_oldActivityId != Guid.Empty)
            {
                // transfer to activity
                _traceSource.TraceTransfer(0, string.Format(CultureInfo.CurrentCulture, "TRANSFER ==> {0} ===", _activityName), _newActivityId);
            }
            Trace.CorrelationManager.ActivityId = _newActivityId;

            _traceSource.Start(_activityName);
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Create activity to contain the other activities
            var ts = new TraceSource("MyServiceTraceSource");
            Guid mainActivityId = Guid.NewGuid();
            Trace.CorrelationManager.ActivityId = mainActivityId;
            ts.TraceEvent(TraceEventType.Start, 0, "Main Activity");

            // Create new activity and transfer to it
            Guid newActivityId = Guid.NewGuid();
            ts.TraceTransfer(0, "Transferring...", newActivityId);
            Trace.CorrelationManager.ActivityId = newActivityId;
            ts.TraceEvent(TraceEventType.Start, 0, "GetHeader Activity");

            // Call operation
            using (MyServiceClient proxy = new MyServiceClient("WSHttpBinding_MyService"))
            {
                try
                {
                    Console.WriteLine(proxy.GetHeader("MyHeader", "http://tempuri.org"));
                    ts.TraceEvent(TraceEventType.Information, 0, "GetHeader succeeded!");
                }
                catch (FaultException<string> ex)
                {
                    Console.WriteLine(ex.Reason);
                    Console.WriteLine(ex.Detail);
                    ts.TraceEvent(TraceEventType.Error, 0,
                        "GetHeader failed.\nReason:{0}\nDetail{1}",
                        ex.Reason, ex.Detail);
                }
            }

            // Transfer back to main activity
            ts.TraceTransfer(666, "Transferring...", mainActivityId);
            ts.TraceEvent(TraceEventType.Stop, 0, "GetHeader Activity");
            Trace.CorrelationManager.ActivityId = mainActivityId;

            // Stop the main activity
            ts.TraceEvent(TraceEventType.Stop, 0, "Main Activity");

            Console.ReadKey();
        }
Пример #3
0
		public TraceCorrelationScope(Guid activity, TraceSource source, bool traceTransfer)
		{
			this.old = Trace.CorrelationManager.ActivityId;

			_Transfered = old != activity && traceTransfer;
			if(_Transfered)
			{
				_Source = source;
				_Source.TraceTransfer(0, "t", activity);
			}
			Trace.CorrelationManager.ActivityId = activity;
		}
Пример #4
0
        public ActivityTraceContext(TraceSource ts, string operationName)
        {
            this.operationName = operationName;
            this.ts = ts;

            Trace.CorrelationManager.StartLogicalOperation(operationName);

            parentActivityId = Trace.CorrelationManager.ActivityId;
            Guid activityId = Guid.NewGuid();

            ts.TraceTransfer(0, "Transfering to " + operationName, activityId);
            Trace.CorrelationManager.ActivityId = activityId;
            ts.TraceEvent(TraceEventType.Start, 0, operationName + " started");
        }
Пример #5
0
        public ScopedActivity(string name, bool transfer = true)
        {
            ActivityId = Guid.NewGuid();
            TraceSource = new TraceSource("EmailingSystem.Service", SourceLevels.All);

            //if transferring from previous activity...
            if (transfer)
            {
                //capture old activity id
                PriorActivityId = Trace.CorrelationManager.ActivityId;

                //tansfer to new activity id with new trace source
                TraceSource.TraceTransfer(0, "Transferring", ActivityId);
            }

            //set activity and trace start event
            Trace.CorrelationManager.ActivityId = ActivityId;
            TraceSource.TraceEvent(TraceEventType.Start, 0, name);
        }
Пример #6
0
        public void TestTrace()
        {
            TraceSource wcfTrace = new TraceSource("System.ServiceModel");
            Guid currentActivity = Trace.CorrelationManager.ActivityId;
            Guid newActivity = Guid.NewGuid();
            Guid newActivity2 = Guid.NewGuid();

            Guid newActivity3 = Guid.NewGuid();

            wcfTrace.TraceEvent(TraceEventType.Start, 100, "[+] Method entered");

            wcfTrace.TraceEvent(TraceEventType.Information, 101, "[+] In current activity");

            wcfTrace.TraceEvent(TraceEventType.Start, 100, "[+] Still in current activity");

            wcfTrace.TraceEvent(TraceEventType.Information, 102, "[+] Still in current activity");

            wcfTrace.TraceTransfer(0, "[+] Start Level 1 activity", newActivity);

            Trace.CorrelationManager.ActivityId = newActivity;

            wcfTrace.TraceEvent(TraceEventType.Information, 103, "[+] Hello from Level 1");

            wcfTrace.TraceEvent(TraceEventType.Warning, 104, "[+] Level 1");
            wcfTrace.TraceEvent(TraceEventType.Error, 103, "[+] Level 1");
            wcfTrace.TraceEvent(TraceEventType.Critical, 105, "[+] Level 1");
            wcfTrace.TraceTransfer(0, "[+] Start Level 2 activity", newActivity2);

            Trace.CorrelationManager.ActivityId = newActivity2;

            wcfTrace.TraceEvent(TraceEventType.Information, 102, "[+] Hello from Level 2");

            wcfTrace.TraceEvent(TraceEventType.Information, 103, "[+] Level 2");

            wcfTrace.TraceTransfer(0, "[+] Jump back to level 1", newActivity);

            Trace.CorrelationManager.ActivityId = newActivity;

            wcfTrace.TraceEvent(TraceEventType.Transfer, 101, "[+] Hello from Level 1");

            wcfTrace.TraceEvent(TraceEventType.Information, 102, "[+] Level 1");

            wcfTrace.TraceTransfer(0, "[+] Jump back to current",

            currentActivity);

            Trace.CorrelationManager.ActivityId = currentActivity;

            wcfTrace.TraceEvent(TraceEventType.Information, 103, "[+] Again in current activity");

            wcfTrace.TraceEvent(TraceEventType.Stop, 101, "[+] Method exited");
        }
Пример #7
0
 public virtual void TraceTransfer(int id, string message, Guid relatedActivityId)
 {
     Execute(() => traceSource.TraceTransfer(id, message, relatedActivityId));
 }
Пример #8
0
        static void Main()
        {
            TraceSource ts = new TraceSource("ClientCalculatorTraceSource");

            // Start the calculator activity
            Guid newGuid = Guid.NewGuid();
            Trace.CorrelationManager.ActivityId = newGuid;
            ts.TraceEvent(TraceEventType.Start, 0, "Calculator Activity");

            // Create a proxy with given client endpoint configuration
            using (CalculatorProxy proxy = new CalculatorProxy())
            {
                // Save the calculator activity id to transfer back and forth from/to it
                Guid originalGuid = Trace.CorrelationManager.ActivityId;

                // Create and start the Add activity                
                // Generate a new activity id
                newGuid = Guid.NewGuid();
                // Transfer from the calculator activity to the new (Add) activity
                // The value for the "from" in the transfer is implicit; it is the activity id 
                // previously set in Trace.CorrelationManager.ActivityId
                // The value for the "to" is explicitly passed as the newGuid parameter
                ts.TraceTransfer(0, "Transferring...", newGuid);
                // Set the new activity id in Trace.CorrelationManager.ActivityId; it is now in scope
                // for subsequently emitted traces
                Trace.CorrelationManager.ActivityId = newGuid;
                // Emit the Start trace for the new activity
                ts.TraceEvent(TraceEventType.Start, 0, "Add Activity");

                // Now make the Add request
                double value1 = 100.00D;
                double value2 = 15.99D;
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client sends Add request message.");
                double result = proxy.Add(value1, value2);

                // Trace that you have received the response
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client receives Add response message.");
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Transfer back to the Calculator activity and stop the current activity
                ts.TraceTransfer(667, "Transferring...", originalGuid);
                ts.TraceEvent(TraceEventType.Stop, 0, "Add Activity");

                // Set the calculator activity back in scope
                Trace.CorrelationManager.ActivityId = originalGuid;


                // Call the Subtract service operation
                newGuid = Guid.NewGuid();
                ts.TraceTransfer(0, "Transferring...", newGuid);
                Trace.CorrelationManager.ActivityId = newGuid;
                ts.TraceEvent(TraceEventType.Start, 0, "Subtract Activity");

                value1 = 100.00D;
                value2 = 15.99D;
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client sends Subtract request message.");
                result = proxy.Subtract(value1, value2);
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client receives Subtract response message.");
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                ts.TraceTransfer(667, "Transferring...", originalGuid);
                ts.TraceEvent(TraceEventType.Stop, 0, "Subtract Activity");
                Trace.CorrelationManager.ActivityId = originalGuid;


                // Call the Multiply service operation
                newGuid = Guid.NewGuid();
                ts.TraceTransfer(0, "Transferring...", newGuid);
                Trace.CorrelationManager.ActivityId = newGuid;
                ts.TraceEvent(TraceEventType.Start, 0, "Multiply Activity");

                value1 = 100.00D;
                value2 = 15.99D;
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client sends Multiply request message.");
                result = proxy.Multiply(value1, value2);
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client receives Multiply response message.");
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                ts.TraceTransfer(667, "Transferring...", originalGuid);
                ts.TraceEvent(TraceEventType.Stop, 0, "Multiply Activity");
                Trace.CorrelationManager.ActivityId = originalGuid;


                // Call the Divide service operation
                newGuid = Guid.NewGuid();
                ts.TraceTransfer(0, "Transferring...", newGuid);
                Trace.CorrelationManager.ActivityId = newGuid;
                ts.TraceEvent(TraceEventType.Start, 0, "Divide Activity");

                value1 = 100.00D;
                value2 = 15.99D;
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client sends Divide request message.");
                result = proxy.Divide(value1, value2);
                ts.TraceEvent(TraceEventType.Information, 0,
                    "Client receives Divide response message.");
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                ts.TraceTransfer(667, "Transferring...", originalGuid);
                ts.TraceEvent(TraceEventType.Stop, 0, "Divide Activity");
                Trace.CorrelationManager.ActivityId = originalGuid;
            }

            ts.TraceEvent(TraceEventType.Stop, 0, "Calculator Activity");

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();

        }
Пример #9
0
        public ActivityScope(TraceSource source, int transferInId, int startId, int transferOutId, int stopId)
        {
            _source = source;
            _startId = startId;
            _stopId = stopId;
            _transferInId = transferInId;
            _transferOutId = transferOutId;

            _previousActivityId = Trace.CorrelationManager.ActivityId;

            // Log Transfer In
            Guid newActivity = Guid.NewGuid();
            if (_source != null)
            {
                _source.TraceTransfer(_transferInId, ActivityScope_Transfer, newActivity);
            }
            Trace.CorrelationManager.ActivityId = newActivity;

            // Log Start Message
            if (_source != null)
            {
                _source.TraceEvent(TraceEventType.Start, _startId, ActivityScope_Start);
            }
        }
Пример #10
0
        public ActivityScope(TraceSource source, int transferInId, int startId, int transferOutId, int stopId,
 string transferInMessage, string startMessage, string transferOutMessage, string stopMessage, string activityName)
        {
            _source = source;
            _startId = startId;
            _stopId = stopId;
            _transferInId = transferInId;
            _transferOutId = transferOutId;

            _previousActivityId = Trace.CorrelationManager.ActivityId;

            _transferInMessage = transferInMessage;
            _startMessage = startMessage;
            _transferOutMessage = transferOutMessage;
            _stopMessage = stopMessage;

            // Log Transfer In
            Guid newActivity = Guid.NewGuid();
            if (_source != null)
            {
                _source.TraceTransfer(_transferInId, _transferInMessage ?? ActivityScope_Transfer, newActivity);
            }
            Trace.CorrelationManager.ActivityId = newActivity;

            // Log Start Message
            if (_source != null)
            {
                var xml = string.Format(@"<TraceRecord Severity='Start' xmlns='http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord'>
                     <TraceIdentifier></TraceIdentifier>
                     <Description>{0}</Description>
                     <AppDomain>{1}</AppDomain>
                     <ExtendedData xmlns='http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord'>
                         <ActivityName>{2}</ActivityName>
                         <ActivityType>Construct</ActivityType>
                     </ExtendedData>
                 </TraceRecord>",
                 _startMessage ?? ActivityScope_Start,
                AppDomain.CurrentDomain.FriendlyName,
                activityName ?? _startMessage ?? ActivityScope_Start
                );

                var doc = new XmlDocument();

                doc.LoadXml(xml);

                _source.TraceData(TraceEventType.Start, _startId, doc.CreateNavigator());

            }
        }
Пример #11
0
 /// <summary>
 /// The switch to activity.
 /// </summary>
 /// <param name="activityId">
 /// The activity id.
 /// </param>
 /// <param name="activityInfo">
 /// The activity info.
 /// </param>
 /// <param name="localTrace">
 /// The local trace.
 /// </param>
 private static void SwitchToActivity(Guid activityId, string activityInfo, TraceSource localTrace)
 {
     var activityMessage = string.IsNullOrEmpty(activityInfo) ? "Starting new Activity..." : activityInfo;
     // Trace.TraceInformation("ID: {0}, Message: {1}", activityId, activityMessage);
     GlobalTrace.TraceTransfer(Counter.Value, activityMessage, activityId);
     localTrace.TraceTransfer(Counter.Value, activityMessage, activityId);
 }