Ejemplo n.º 1
0
        public void CreateTraceEventRecordFromXmlSample(string fileName)
        {
            string testMessageFile = Path.Combine(testMessageFolder, fileName);

            using (FileStream fileStream = new FileStream(testMessageFile, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings()
                {
                    CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true, ValidationType = ValidationType.None
                };
                XmlReader xmlFileReader = XmlReader.Create(fileStream, readerSettings);
                XElement  eventDataXml  = XElement.Load(xmlFileReader);

                var traceEventRecords = eventDataXml.Descendants(XName.Get("TraceEvents", eventDataXml.Name.Namespace.NamespaceName)).Descendants(XName.Get("TraceEventRecord", WellKnownNamespace.DataContracts.General));

                foreach (var r in traceEventRecords)
                {
                    TraceEventRecord eventRecord = TraceEventRecord.Create(XmlReader.Create(r.CreateReader(), readerSettings));

                    Assert.AreNotEqual <DateTime>(default(DateTime), eventRecord.DateTime, "Unexpected DateTime value");
                    Assert.AreNotEqual <int>(default(Int32), eventRecord.EventId, "Unexpected EventId value");
                    Assert.AreNotEqual <int>(default(Int32), eventRecord.ProcessId, "Unexpected ProcessId value");
                    Assert.AreNotEqual <int>(default(Int32), eventRecord.ThreadId, "Unexpected ThreadId value");
                    Assert.AreNotEqual <long>(default(Int64), eventRecord.Timestamp, "Unexpected ThreadId value");
                    Assert.AreEqual <string>("APPFABRIC-CAT-01", eventRecord.MachineName, "Unexpected MachineName value");
                    Assert.AreEqual <string>("WaWorkerHost", eventRecord.ProcessName, "Unexpected ProcessName value");
                    Assert.AreEqual <string>("WorkerRoleComponent", eventRecord.EventSource, "Unexpected EventSource value");
                    Assert.IsFalse(String.IsNullOrEmpty(eventRecord.Message), "Message text is null or empty");
                    Assert.AreEqual <TraceEventType>(TraceEventType.Information, eventRecord.EventType, "Unexpected EventType value");
                }
            }
        }
Ejemplo n.º 2
0
        public void TestMessageBufferSend()
        {
            int eventCount = 0;
            ServiceBusEndpointInfo diagEndpointInfo = ApplicationConfiguration.Current.ServiceBusSettings.Endpoints[diagnosticEventQueue];

            Assert.IsNotNull(diagEndpointInfo, "{0} service bus endpoint definition has not been found", diagnosticEventQueue);

            try
            {
                string randomQueueName = Guid.NewGuid().ToString();

                using (ReliableServiceBusQueue <TraceEventRecord> sbQueue = new ReliableServiceBusQueue <TraceEventRecord>(randomQueueName, diagEndpointInfo))
                {
                    for (int i = 0; i < 100; i++)
                    {
                        sbQueue.Send(TraceEventRecord.Create(this.GetType().Name, TraceEventType.Information, 0, String.Format("Test event #{0}", i)));
                        eventCount++;
                    }
                }
            }
            finally
            {
                Trace.WriteLine(String.Format("Event count = {0}", eventCount));
            }
        }
Ejemplo n.º 3
0
        private void EmitHeartbeatEvent()
        {
            // Construct an event marked as Informational (consider using Critical event type as most logging/tracing configurations should allow critical events to come through).
            TraceEventRecord heartbeatEvent = TraceEventRecord.Create(CloudEnvironment.CurrentRoleInstanceId, TraceEventType.Information, InstrumentationUtility.SystemEventId.Heartbeat, String.Format(TraceLogMessages.WorkerRoleHeartBeatInfo, CloudEnvironment.CurrentRoleInstanceId, this.runTimeStopwatch.Elapsed));

            // Log the heartbeat event via WorkerRoleComponent trace manager.
            TraceManager.WorkerRoleComponent.TraceEvent(heartbeatEvent);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the custom runtime task component to process the input message and returns the result message.
        /// </summary>
        /// <param name="pContext">A reference to <see cref="Microsoft.BizTalk.Component.Interop.IPipelineContext"/> object that contains the current pipeline context.</param>
        /// <param name="pInMsg">A reference to <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessage"/> object that contains the message to process.</param>
        /// <returns>A reference to the returned <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessage"/> object which will contain the output message.</returns>
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            Guard.ArgumentNotNull(pContext, "pContext");
            Guard.ArgumentNotNull(pInMsg, "pInMsg");

            var callToken = TraceManager.PipelineComponent.TraceIn();

            if (pInMsg.BodyPart != null)
            {
                Stream messageDataStream = BizTalkUtility.EnsureSeekableStream(pInMsg, pContext);

                if (messageDataStream != null)
                {
                    try
                    {
                        XmlReaderSettings readerSettings = new XmlReaderSettings()
                        {
                            CloseInput = false, CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true, ValidationType = ValidationType.None
                        };

                        using (XmlReader messageDataReader = XmlReader.Create(messageDataStream, readerSettings))
                        {
                            XElement            eventDataXml = XElement.Load(messageDataReader);
                            TraceEventRecord    eventRecord;
                            ITraceEventProvider traceProvider = null;

                            var traceEventRecords = eventDataXml.Descendants(XName.Get(WellKnownContractMember.MessageParameters.TraceEvents, eventDataXml.Name.Namespace.NamespaceName)).Descendants(XName.Get(traceEventRecordAttr.Name, traceEventRecordAttr.Namespace));

                            foreach (var r in traceEventRecords)
                            {
                                eventRecord   = TraceEventRecord.Create(XmlReader.Create(r.CreateReader(), readerSettings));
                                traceProvider = TraceManager.Create(eventRecord.EventSourceId);

                                if (traceProvider != null)
                                {
                                    traceProvider.TraceEvent(eventRecord);
                                }
                                else
                                {
                                    object[] parameters = new object[] { eventRecord.Message, eventRecord.EventId, eventRecord.EventSource, eventRecord.MachineName, eventRecord.ProcessName, eventRecord.ProcessId, eventRecord.ThreadId, eventRecord.DateTime.ToString("o") };
                                    TraceManager.PipelineComponent.TraceWarning(TraceLogMessages.NoTraceProviderFound, eventRecord.EventSource, String.Format(CultureInfo.InvariantCulture, Resources.TraceEventMessageFormatString, parameters));
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (messageDataStream.CanSeek)
                        {
                            messageDataStream.Seek(0, SeekOrigin.Begin);
                        }
                    }
                }
            }

            TraceManager.PipelineComponent.TraceOut(callToken);
            return(pInMsg);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes trace information, a data object and event information to the listener specific output.
        /// </summary>
        /// <param name="eventCache">A TraceEventCache object that contains the current process ID, thread ID, and stack trace information.</param>
        /// <param name="source">A name used to identify the output, typically the name of the application that generated the trace event.</param>
        /// <param name="eventType">One of the TraceEventType values specifying the type of event that has caused the trace.</param>
        /// <param name="id">A numeric identifier for the event.</param>
        /// <param name="data">The trace data to emit.</param>
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            // Extract log entry from data parameter
            LogEntry logEntry = data as LogEntry;

            if (logEntry != null)
            {
                TraceEvent(TraceEventRecord.Create(logEntry));
            }
            else
            {
                base.TraceData(eventCache, source, eventType, id, data);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Writes trace information, a message, and event information to the listener specific output.
 /// </summary>
 /// <param name="eventCache">A TraceEventCache object that contains the current process ID, thread ID, and stack trace information.</param>
 /// <param name="source">A name used to identify the output, typically the name of the application that generated the trace event.</param>
 /// <param name="eventType">One of the TraceEventType values specifying the type of event that has caused the trace.</param>
 /// <param name="id">A numeric identifier for the event.</param>
 /// <param name="message">A message to write.</param>
 public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
 {
     TraceEvent(TraceEventRecord.Create(eventCache, source, eventType, id, message));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes the specified message to the trace.
 /// </summary>
 /// <param name="message">The message to write.</param>
 public override void Write(string message)
 {
     TraceEvent(TraceEventRecord.Create(ListenerName, TraceEventType.Information, InstrumentationUtility.SystemEventId.Info, message));
 }