Exemplo n.º 1
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     var d = new ConsoleEventData();
     d.Name = eventData.EventName;
     d.Message = getMessage(eventData);
     Messages.Add(d);
 }
Exemplo n.º 2
0
        /// <summary>
        /// We override this method to get a callback on every event we subscribed to with EnableEvents
        /// </summary>
        /// <param name="eventData"></param>
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            // report all event information
            Out.Write("  Event {0} ", eventData.EventName);

            // Events can have formatting strings 'the Message property on the 'Event' attribute.
            // If the event has a formatted message, print that, otherwise print out argument values.
            if (eventData.Message != null)
                Out.WriteLine(eventData.Message, eventData.Payload != null ? eventData.Payload.ToArray() : null);
            else
            {
                string[] sargs = eventData.Payload != null ? eventData.Payload.Select(o => o.ToString()).ToArray() : null;
                Out.WriteLine("({0}).", sargs != null ? string.Join(", ", sargs) : "");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// We override this method to get a callback on every event we subscribed to with EnableEvents
        /// </summary>
        /// <param name="eventData"></param>
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            // report all event information
            Out.Write("  Event {0} ", eventData.EventName);

            // Don't display activity information, as that's not used in the demos
            // Out.Write(" (activity {0}{1}) ", ShortGuid(eventData.ActivityId),
            //                                  eventData.RelatedActivityId != Guid.Empty ? "->" + ShortGuid(eventData.RelatedActivityId) : "");

            // Events can have formatting strings 'the Message property on the 'Event' attribute.
            // If the event has a formatted message, print that, otherwise print out argument values.
            if (eventData.Message != null)
                Out.WriteLine(eventData.Message, eventData.Payload.ToArray());
            else
                Out.WriteLine("({0}).", eventData.Payload != null ? string.Join(", ", eventData.Payload) : "");
        }
Exemplo n.º 4
0
 public TestBenchmark()
 {
     eventArgs = (EventWrittenEventArgs)Activator.CreateInstance(typeof(EventWrittenEventArgs), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, (Binder)null, new object[] { null }, null);
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 protected override void OnAlways(EventWrittenEventArgs eventData)
 {
 }
Exemplo n.º 6
0
 /// <inheritdoc />
 protected override void OnCritical(EventWrittenEventArgs eventData)
 {
     LogAzureDevOpsIssue(eventData, "error");
 }
Exemplo n.º 7
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     //Console.WriteLine(eventData.Message, eventData.Payload.ToArray());
     ts.TraceEvent(ConvertLevel(eventData.Level), eventData.EventId, eventData.Message, eventData.Payload.ToArray());
 }
 /// <summary>
 /// Gets called after every EventSource event. We capture that event's data and log it
 /// using the appropiate strategy for the current linux host.
 /// </summary>
 /// <param name="eventData">The EventSource event data, for logging.</param>
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     this.logger.Log(eventData);
 }
Exemplo n.º 9
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     // OnEventWritten is abstract in .NET Framework <= 461
     base.OnEventWritten(eventData);
     _forwardTo?.OnEvent?.Invoke(new EventListenerEvent(eventData));
 }
Exemplo n.º 10
0
 private void mListenerEventWritten(object sender, EventWrittenEventArgs eventData)
 {
     OnEvent(new EventListenerEvent(eventData));
 }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     Debug.WriteLine(eventData.Payload[0]);
     TestLogListener.ProcessMessage(TestLogListener.MapLogLevel(eventData.Level), eventData.Payload[0].ToString());
 }
Exemplo n.º 12
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     Console.Write("Activity: {0} ", Trace.CorrelationManager.ActivityId);
     Console.WriteLine(eventData.Message, eventData.Payload.ToArray());
 }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     WrittenEntries.Add(EventEntry.Create(eventData, EventSourceSchemaCache.Instance.GetSchema(eventData.EventId, eventData.EventSource)));
 }
Exemplo n.º 14
0
		protected override void OnEventWritten(EventWrittenEventArgs eventData)
		{
			_events.Add(eventData);
		}
        private static void VerifyEventId(MethodInfo eventMethod, EventWrittenEventArgs actualEvent)
        {
            int expectedEventId = GetEventAttribute(eventMethod).EventId;

            AssertEqual(expectedEventId, actualEvent.EventId, "EventId");
        }
Exemplo n.º 16
0
 internal EventListenerEvent(EventWrittenEventArgs data) => Data = data;
Exemplo n.º 17
0
        /// <summary>
        /// A helper that can run the test under a variety of conditions
        /// * Whether the eventSource is enabled at startup
        /// * Whether the listener is ETW or an EventListern
        /// * Whether the ETW output is self describing or not.
        /// </summary>
        private void Test_Bad_EventSource_Startup(bool onStartup, Listener listener, EventSourceSettings settings)
        {
            var eventSourceName = typeof(BadEventSource_MismatchedIds).Name;

            Debug.WriteLine("***** Test_BadEventSource_Startup(OnStartUp: " + onStartup + " Listener: " + listener + " Settings: " + settings + ")");

            // Activate the source before the source exists (if told to).
            if (onStartup)
            {
                listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
            }

            var events = new List <Event>();

            listener.OnEvent = delegate(Event data) { events.Add(data); };

            using (var source = new BadEventSource_MismatchedIds(settings))
            {
                Assert.Equal(eventSourceName, source.Name);
                // activate the source after the source exists (if told to).
                if (!onStartup)
                {
                    listener.EventSourceCommand(eventSourceName, EventCommand.Enable);
                }
                source.Event1(1);       // Try to send something.
            }
            listener.Dispose();

            // Confirm that we get exactly one event from this whole process, that has the error message we expect.
            Assert.Equal(1, events.Count);
            Event _event = events[0];

            Assert.Equal("EventSourceMessage", _event.EventName);
            string message = _event.PayloadString(0, "message");

            Debug.WriteLine(string.Format("Message=\"{0}\"", message));
            // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_MismatchedIds: Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent. "
            if (!PlatformDetection.IsNetFramework) // .NET Framework has typo
            {
                Assert.Matches("Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent", message);
            }

            // Validate the details of the EventWrittenEventArgs object
            if (_event is EventListenerListener.EventListenerEvent elEvent)
            {
                EventWrittenEventArgs ea = elEvent.Data;
                Assert.NotNull(ea);
                Assert.Equal(EventSource.CurrentThreadActivityId, ea.ActivityId);
                Assert.Equal(EventChannel.None, ea.Channel);
                Assert.Equal(0, ea.EventId);
                Assert.Equal("EventSourceMessage", ea.EventName);
                Assert.NotNull(ea.EventSource);
                Assert.Equal(EventKeywords.None, ea.Keywords);
                Assert.Equal(EventLevel.LogAlways, ea.Level);
                Assert.Equal((EventOpcode)0, ea.Opcode);
                Assert.NotNull(ea.Payload);
                Assert.NotNull(ea.PayloadNames);
                Assert.Equal(ea.PayloadNames.Count, ea.Payload.Count);
                Assert.Equal(Guid.Empty, ea.RelatedActivityId);
                Assert.Equal(EventTags.None, ea.Tags);
                Assert.Equal(EventTask.None, ea.Task);
                Assert.InRange(ea.TimeStamp, DateTime.MinValue, DateTime.MaxValue);
                Assert.Equal(0, ea.Version);
            }
        }
 protected override void OnEventWritten(
     EventWrittenEventArgs eventData) =>
 Console.WriteLine(eventData.Message, eventData.Payload[0]);
 protected override void OnEventWritten(EventWrittenEventArgs eventArgs)
 {
     this.Sender.SubmitEvent(eventArgs.ToEventData());
 }
Exemplo n.º 20
0
 public static T GetProperty <T>(this EventWrittenEventArgs data, string propName)
 => (T)data.Payload[data.PayloadNames.IndexOf(propName)];
Exemplo n.º 21
0
        /// <summary>
        /// Creates a new <see cref="EventEntry"/> instance based on the <paramref name="args"/> and the <paramref name="schema"/>.
        /// </summary>
        /// <param name="args">The <see cref="EventWrittenEventArgs"/> representing the event to log.</param>
        /// <param name="schema">The <see cref="EventSchema"/> for the source originating the event.</param>
        /// <returns>An entry describing the event.</returns>
        public static EventEntry Create(EventWrittenEventArgs args, EventSchema schema)
        {
            Guard.ArgumentNotNull(args, "args");
            Guard.ArgumentNotNull(schema, "schema");

            var timestamp = DateTimeOffset.Now;

            // TODO: validate whether we want to do this pro-actively or should we wait until the
            // last possible moment (as the formatted message might not be used in a sink).
            string formattedMessage = null;
            if (args.Message != null)
            {
                formattedMessage = string.Format(CultureInfo.InvariantCulture, args.Message, args.Payload.ToArray());
            }

            return new EventEntry(
                args.EventSource.Guid,
                args.EventId,
                formattedMessage,
                args.Payload,
                timestamp,
                CurrentProcessId,
                ProcessPropertyAccess.GetCurrentThreadId(),
                ActivityIdPropertyAccess.GetActivityId(args),
                ActivityIdPropertyAccess.GetRelatedActivityId(args),
                schema);
        }
Exemplo n.º 22
0
 /// <inheritdoc/>
 protected override void OnEventWritten(EventWrittenEventArgs eventData) => EventsInformation.Add(eventData);
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     this.Events.Enqueue(eventData);
 }
Exemplo n.º 24
0
 /// <inheritdoc />
 protected override void OnInformational(EventWrittenEventArgs eventData)
 {
 }
Exemplo n.º 25
0
 static string getMessage(EventWrittenEventArgs d)
 {
     var objects = new object[d.Payload.Count];
     d.Payload.CopyTo(objects, 0);
     return string.Format(d.Message, objects);
 }
Exemplo n.º 26
0
 /// <inheritdoc />
 protected override void OnVerbose(EventWrittenEventArgs eventData)
 {
 }
Exemplo n.º 27
0
 /// <inheritdoc />
 protected override void OnWarning(EventWrittenEventArgs eventData)
 {
     LogAzureDevOpsIssue(eventData, "warning");
 }
Exemplo n.º 28
0
 /// <inheritdoc />
 protected override void OnSuppressedWarning(EventWrittenEventArgs eventData)
 {
 }
Exemplo n.º 29
0
        protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWrittenEventArgs eventData)
        {
#pragma warning disable IDE0007 // Use implicit type
            // Explicit type here to drop the object? signature of payload elements
            ReadOnlyCollection <object> payload = eventData.Payload !;
#pragma warning restore IDE0007 // Use implicit type

            switch (eventData.EventId)
            {
            case 1:
                Debug.Assert(eventData.EventName == "RequestStart" && payload.Count == 7);
                {
                    var scheme        = (string)payload[0];
                    var host          = (string)payload[1];
                    var port          = (int)payload[2];
                    var pathAndQuery  = (string)payload[3];
                    var versionMajor  = (int)(byte)payload[4];
                    var versionMinor  = (int)(byte)payload[5];
                    var versionPolicy = (HttpVersionPolicy)payload[6];
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestStart(eventData.TimeStamp, scheme, host, port, pathAndQuery, versionMajor, versionMinor, versionPolicy);
                    }
                }
                break;

            case 2:
                Debug.Assert(eventData.EventName == "RequestStop" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestStop(eventData.TimeStamp);
                    }
                }
                break;

            case 3:
                Debug.Assert(eventData.EventName == "RequestFailed" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestFailed(eventData.TimeStamp);
                    }
                }
                break;

            case 4:
                Debug.Assert(eventData.EventName == "ConnectionEstablished" && payload.Count == 2);
                {
                    var versionMajor = (int)(byte)payload[0];
                    var versionMinor = (int)(byte)payload[1];
                    foreach (var consumer in consumers)
                    {
                        consumer.OnConnectionEstablished(eventData.TimeStamp, versionMajor, versionMinor);
                    }
                }
                break;

            case 5:
                Debug.Assert(eventData.EventName == "ConnectionClosed" && payload.Count == 2);
                break;

            case 6:
                Debug.Assert(eventData.EventName == "RequestLeftQueue" && payload.Count == 3);
                {
                    var timeOnQueue  = TimeSpan.FromMilliseconds((double)payload[0]);
                    var versionMajor = (int)(byte)payload[1];
                    var versionMinor = (int)(byte)payload[2];
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestLeftQueue(eventData.TimeStamp, timeOnQueue, versionMajor, versionMinor);
                    }
                }
                break;

            case 7:
                Debug.Assert(eventData.EventName == "RequestHeadersStart" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestHeadersStart(eventData.TimeStamp);
                    }
                }
                break;

            case 8:
                Debug.Assert(eventData.EventName == "RequestHeadersStop" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestHeadersStop(eventData.TimeStamp);
                    }
                }
                break;

            case 9:
                Debug.Assert(eventData.EventName == "RequestContentStart" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestContentStart(eventData.TimeStamp);
                    }
                }
                break;

            case 10:
                Debug.Assert(eventData.EventName == "RequestContentStop" && payload.Count == 1);
                {
                    var contentLength = (long)payload[0];
                    foreach (var consumer in consumers)
                    {
                        consumer.OnRequestContentStop(eventData.TimeStamp, contentLength);
                    }
                }
                break;

            case 11:
                Debug.Assert(eventData.EventName == "ResponseHeadersStart" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnResponseHeadersStart(eventData.TimeStamp);
                    }
                }
                break;

            case 12:
                Debug.Assert(eventData.EventName == "ResponseHeadersStop" && payload.Count == 0);
                {
                    foreach (var consumer in consumers)
                    {
                        consumer.OnResponseHeadersStop(eventData.TimeStamp);
                    }
                }
                break;
            }
        }
Exemplo n.º 30
0
 public static CosmosEventMetadata AsDependency(EventWrittenEventArgs eventData)
 {
     return(CosmosEventDataConverter.ExtractData(eventData).AsDependency());
 }
        private static void VerifyOperationEvent(OperationTelemetry expectedOperation, string expectedName, EventOpcode expectedOpCode, EventWrittenEventArgs actualEvent)
        {
            Assert.AreEqual(expectedOpCode, actualEvent.Opcode);
#if !NET45
            Assert.AreEqual(expectedName, actualEvent.EventName);
#endif
            VerifyOperationPayload(expectedOperation, actualEvent.Payload);
        }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     this.WriteEvent(eventData);
 }
        private static void VerifyEventLevel(MethodInfo eventMethod, EventWrittenEventArgs actualEvent)
        {
            EventLevel expectedLevel = GetEventAttribute(eventMethod).Level;

            AssertEqual(expectedLevel, actualEvent.Level, "Level");
        }
 protected abstract void WriteEvent(EventWrittenEventArgs eventData);
Exemplo n.º 35
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     this.EventsReceived.Add(eventData.EventName);
 }
        private string FormatPayload(EventWrittenEventArgs eventData)
        {
            var items = FormatPayloadItems(eventData.PayloadNames, eventData.Payload, prefix: null);

            return(string.Join(", ", items));
        }
Exemplo n.º 37
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     IDs.Add(eventData.EventId);
 }
Exemplo n.º 38
0
        public static void DroppedIncompleteStateMachine_RaisesIncompleteAsyncMethodEvent()
        {
            RemoteExecutor.Invoke(() =>
            {
                using (var listener = new TestEventListener("System.Threading.Tasks.TplEventSource", EventLevel.Verbose))
                {
                    var events = new ConcurrentQueue <EventWrittenEventArgs>();
                    listener.RunWithCallback(events.Enqueue, () =>
                    {
                        NeverCompletes();
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        GC.WaitForPendingFinalizers();
                    });

                    // To help diagnose https://github.com/dotnet/runtime/issues/2198
                    // Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
                    var sb = new StringBuilder();
                    foreach (EventWrittenEventArgs ev in events)
                    {
                        if (ev.EventId == 0)
                        {
                            sb.AppendLine("Events contained unexpected event:")
                            .AppendLine($"ActivityId: {ev.ActivityId}")
                            .AppendLine($"Channel: {ev.Channel}")
                            .AppendLine($"EventId: {ev.EventId}")
                            .AppendLine($"EventName: {ev.EventName}")
                            .AppendLine($"EventSource: {ev.EventSource}")
                            .AppendLine($"Keywords: {ev.Keywords}")
                            .AppendLine($"Level: {ev.Level}")
                            .AppendLine($"Message: {ev.Message}")
                            .AppendLine($"Opcode: {ev.Opcode}")
                            .AppendLine($"OSThreadId: {ev.OSThreadId}")
                            .AppendLine($"Payload: {(ev.Payload != null ? string.Join(", ", ev.Payload) : "(null)")}")
                            .AppendLine($"PayloadNames: {(ev.PayloadNames != null ? string.Join(", ", ev.PayloadNames) : "(null)")}")
                            .AppendLine($"RelatedActivityId: {ev.RelatedActivityId}")
                            .AppendLine($"Tags: {ev.Tags}")
                            .AppendLine($"Task: {ev.Task}")
                            .AppendLine($"TimeStamp: {ev.TimeStamp}")
                            .AppendLine($"Version: {ev.Version}")
                            .AppendLine();
                        }
                    }
                    if (sb.Length > 0)
                    {
                        throw new XunitException(sb.ToString());
                    }

                    EventWrittenEventArgs iam = events.SingleOrDefault(e => e.EventName == "IncompleteAsyncMethod");
                    Assert.NotNull(iam);
                    Assert.NotNull(iam.Payload);

                    string description = iam.Payload[0] as string;
                    Assert.NotNull(description);
                    Assert.Contains(nameof(NeverCompletesAsync), description);
                    Assert.Contains("__state", description);
                    Assert.Contains("local1", description);
                    Assert.Contains("local2", description);
                    Assert.Contains("42", description);
                    Assert.Contains("stored data", description);
                }
            }).Dispose();
        }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// This method records the events from event sources to a local file, which is provided as a stream object by
 /// SelfDiagnosticsConfigRefresher class. The file size is bound to a upper limit. Once the write position
 /// reaches the end, it will be reset to the beginning of the file.
 /// </summary>
 /// <param name="eventData">Data of the EventSource event.</param>
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     // TODO: retrieve the file stream object from configRefresher and write to it
 }
            protected override void OnEventWritten(EventWrittenEventArgs eventData)
            {
                this.EventData = eventData;

                try
                {
                    if (this.TypeOrderOffset != -1)
                    {
                        this.CheckParametersOrder();
                        return;
                    }

                    this.CheckPayload();
                }
                catch (Exception e)
                {
                    this.Error = e;
                }
            }
Exemplo n.º 42
0
        private void SendHeardException(EventWrittenEventArgs args, string level)
        {
            var output = args.ToString();

            _metrics.Client.TrackTrace($"EventWritten: {output} Level: {level}.");
        }
Exemplo n.º 43
0
 public static Guid GetRelatedActivityId(EventWrittenEventArgs args)
 {
     return RelatedActivityIdAccessor(args);
 }
Exemplo n.º 44
0
		protected override void OnEventWritten(EventWrittenEventArgs eventData)
		{
			Console.Write("Activity: {0} ", EventActivityScope.CurrentActivityId);
			Console.WriteLine(eventData.Message, eventData.Payload.ToArray());
		}