protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            var test = new EventInstance(eventData.EventId, (int)eventData.Task, EventLogEntryType.Warning);
            _eventLog.WriteEvent(test, new string[] { "OpCode=1" });

            _eventLog.WriteEntry("Event Occurring", EventLogEntryType.Information, eventData.EventId, (short)eventData.Task);
        }
        static ETWEvent FromEventSourceEvent(EventWrittenEventArgs item, Dictionary<string, string> additionalProperties)
        {
            var data = new Dictionary<string, object>();

            for (var i = 0; i < item.PayloadNames.Count; i++)
                data.Add(item.PayloadNames[i], item.Payload[i]);

            if (additionalProperties != null)
            {
                foreach (var property in additionalProperties)
                {
                    if(!data.ContainsKey(property.Key))
                        data.Add(property.Key, property.Value);
                }
            }

            return new ETWEvent
            {
                Provider = item.EventSource.Name,
                EventName = item.EventName,
                EventId = (ushort)item.EventId,
                Message = item.DumpFormattedMessage() ?? "none",
                Level = item.Level.ToString(),
                ActivityId = item.ActivityId,
                Timestamp = DateTime.UtcNow,
                Fields = data
            };
        }
        /// <summary>
        /// Called whenever an event has been written by an event source for which the event listener has enabled events.
        /// </summary>
        /// <param name="eventData">The event arguments that describe the event.</param>
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            if (eventData == null || eventData.Payload == null)
            {
                return;
            }

            try
            {
                switch (eventData.EventId)
                {
                    case BeginGetResponseEventId:
                        this.OnBeginGetResponse(eventData);
                        break;
                    case EndGetResponseEventId:
                        this.OnEndGetResponse(eventData);
                        break;
                    case BeginGetRequestStreamEventId:
                        this.OnBeginGetRequestStream(eventData);
                        break;
                    case EndGetRequestStreamEventId:
                        break;
                }
            }
            catch (Exception exc)
            {
                DependencyCollectorEventSource.Log.CallbackError(0, "OnEventWritten", exc);
            }
        }
예제 #4
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     if (eventData.EventId == (int)SharedLogEventId.PipStatus)
     {
         ReportStatus();
     }
 }
        /// <summary>
        /// Implements on end callback of http module.
        /// </summary>
        public void OnEndRequest(EventWrittenEventArgs args)
        {
            if (this.telemetryClient == null)
            {
                throw new InvalidOperationException();
            }

            var platformContext = this.ResolvePlatformContext();

            var requestTelemetry = platformContext.ReadOrCreateRequestTelemetryPrivate();
            requestTelemetry.Stop();

            // Success will be set in Sanitize on the base of ResponseCode 
            if (string.IsNullOrEmpty(requestTelemetry.ResponseCode))
            {
                requestTelemetry.ResponseCode = platformContext.Response.StatusCode.ToString(CultureInfo.InvariantCulture);
            }

            if (requestTelemetry.Url == null)
            {
                requestTelemetry.Url = platformContext.Request.UnvalidatedGetUrl();
            }

            if (string.IsNullOrEmpty(requestTelemetry.HttpMethod))
            {
                requestTelemetry.HttpMethod = platformContext.Request.HttpMethod;
            }

            this.telemetryClient.TrackRequest(requestTelemetry);
        }
        /// <summary>
        /// Implements on error callback of http module.
        /// </summary>
        public void OnError(EventWrittenEventArgs args)
        {
            if (this.telemetryClient == null)
            {
                throw new InvalidOperationException();
            }

            var platformContext = this.ResolvePlatformContext();
            var errors = platformContext.AllErrors;

            if (errors != null && errors.Length > 0)
            {
                foreach (Exception exp in errors)
                {
                    var exceptionTelemetry = new ExceptionTelemetry(exp)
                    {
                        HandledAt = ExceptionHandledAt.Platform
                    };

                    if (platformContext.Response.StatusCode >= 500)
                    {
                        exceptionTelemetry.SeverityLevel = SeverityLevel.Critical;
                    }

                    this.telemetryClient.TrackException(exceptionTelemetry);
                }
            }
        }
        public static ConsoleColor?GetColorMap(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs, bool isBackgroundWhite)
        {
            switch (eventArgs.Level)
            {
            case EventLevel.Critical:
                return(ConsoleColor.Magenta);

            case EventLevel.Error:
                return(ConsoleColor.Red);

            case EventLevel.Informational:
                return(ConsoleColor.Green);

            case EventLevel.Verbose:
                return(ConsoleColor.Gray);

            case EventLevel.Warning:
                return(isBackgroundWhite ? ConsoleColor.DarkRed : ConsoleColor.Yellow);

            case EventLevel.LogAlways:
                return(isBackgroundWhite ? ConsoleColor.Black : ConsoleColor.White);

            default:
                return(null);
            }
        }
예제 #8
0
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            LastEvent = eventData;

            Debug.Write(String.Format("Event {0} ", eventData.EventId));
            Debug.Write(String.Format(" (activity {0}{1}) ", eventData.ActivityId, eventData.RelatedActivityId != null ? "->" + eventData.RelatedActivityId : ""));
            Debug.WriteLine(String.Format(" ({0}).", eventData.Payload != null ? string.Join(", ", eventData.Payload) : ""));
        }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     Console.WriteLine("Event: {0}", eventData.Message);
     foreach (var payloadItem in eventData.Payload)
     {
         Console.WriteLine(payloadItem);
     }
 }
예제 #10
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     this.Events.Add(eventData);
     EventHandler handler = this.EventWritten;
     if (handler != null)
     {
         handler(this, EventArgs.Empty);
     }
 }
예제 #11
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     StringBuilder builder = new StringBuilder(50);
     builder.AppendFormat("Event {0}. Payload:", eventData.EventId);
     foreach (object arg in eventData.Payload)
     {
         builder.Append(arg);
     }
     Console.WriteLine(builder.ToString());
 }
        protected override void OnEventWritten(EventWrittenEventArgs e)
        {
            var output = string.Format(Format, e.Level, DateTime.Now, e.Payload[0]);

            lock (m_syncRoot)
            {
                m_writer.WriteLine(output);
                m_writer.Flush();
            }
        }
        /// <summary>
        /// Get PeyloadNames from EventSource manifest.
        /// </summary>
        public static ReadOnlyCollection <string> GetPayloadNames(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var source    = eventArgs.EventSource;
            var templates = GetEventSchemaPortions(source);

            EventSchemaPortion portion;

            return(templates.TryGetValue(eventArgs.EventId, out portion)
                ? portion.Payload
                : eventArgs.PayloadNames);
        }
        /// <summary>
        /// Get TaskName from EventSource manifest.
        /// </summary>
        public static string GetTaskName(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var source    = eventArgs.EventSource;
            var templates = GetEventSchemaPortions(source);

            EventSchemaPortion portion;

            return(templates.TryGetValue(eventArgs.EventId, out portion)
                ? portion.TaskName
                : eventArgs.Task.ToString()); // can't get TaskName...
        }
        public static string DumpFormattedMessage(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var msg = eventArgs.Message;

            if (string.IsNullOrWhiteSpace(msg))
            {
                return(msg);
            }

            return(string.Format(msg, eventArgs.Payload.ToArray()));
        }
 private void OnEventWritten(EventWrittenEventArgs eventData)
 {
     try
     {
         var serializedEvent = JsonConvert.SerializeObject(eventData);
         PushEvent(serializedEvent);
     }
     catch (Exception e)
     {
         Utilities.WriteError(e.ToString());
     }
 }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     var logEntry = LogEntryMapper.Map(eventData);
     try
     {
         LoggingRepository.Save(logEntry);
     }
     catch (Exception e)
     {
         Trace.TraceError("Could not save log to database: " + e.Message + " : " + JsonSerializer.SerializeObject(logEntry));
     }
 }
예제 #18
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     if (m_StorageFile == null)
     {
         return;
     }
     var lines = new List<string>();
     var newFormatedLine = string.Format(m_Format, DateTime.Now, eventData.Level, eventData.EventId, eventData.Payload[0]);
     Debug.WriteLine(newFormatedLine);
     lines.Add(newFormatedLine);
     WriteToFile(lines);
 }
예제 #19
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Called whenever an event has been written by an event source for which the event listener has enabled events.
        /// </summary>
        /// <param name="eventData">The event data.</param>
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            if (eventData != null)
            {
#if DEBUG
                const string Format = "{0:yyyy-MM-dd HH\\:mm\\:ss\\.fff} {1, -13} [{3}] {6} : {2}";
                var p = eventData.Payload;
                var newFormatedLine = string.Format(
                    CultureInfo.InvariantCulture, Format, DateTime.Now, eventData.Level, p[0], p[1], p[2], p[3], p[4]);
                Debug.WriteLine(newFormatedLine);
#endif
            }
        }
예제 #20
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     lock (Console.Out)
     {
         string text = $"[{eventData.EventSource.Name}-{eventData.EventId}]{(eventData.Payload != null ? $" ({string.Join(", ", eventData.Payload)})." : "")}";
         if (_eventFilter != null && text.Contains(_eventFilter))
         {
             ConsoleColor origForeground = Console.ForegroundColor;
             Console.ForegroundColor = ConsoleColor.DarkYellow;
             Console.WriteLine(text);
             Console.ForegroundColor = origForeground;
         }
     }
 }
예제 #21
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     var errorLogEntry = LogEntryMapper.MapError(eventData);
     var payload = new List<object>();
     try
     {
         LoggingRepository.Save(errorLogEntry);
     }
     catch(Exception gatewayException)
     {
         payload.Add(gatewayException.GetType().Name);
         payload.Add(gatewayException.Message);
         Trace.TraceError(JsonSerializer.SerializeObject(errorLogEntry, true, true));
     }
 }
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     foreach(var pl in eventData.Payload)
     {
         var dict = pl as IDictionary<string, object>;
         if(dict != null)
         {
             var rex = new RabbitMqExceptionDetail(dict);
             Console.WriteLine("{0}: {1}", eventData.Level, rex.ToString());
         }
         else
         {
             Console.WriteLine("{0}: {1}", eventData.Level, pl.ToString());
         }
     }
 }
예제 #23
0
 public static LogEntry Map(EventWrittenEventArgs source)
 {
     return new LogEntry
     {
         Created = DateTime.UtcNow,
         EventId = source.EventId,
         EventSource = JsonSerializer.DeserializeObject<EventSource>(JsonSerializer.SerializeObject(source.EventSource)),
         Id = Guid.NewGuid(),
         Opcode = (Opcodes)source.Opcode,
         Keyword = (Keywords)source.Keywords,
         Level = (Levels)source.Level,
         Message = source.Message,
         Task = (Tasks)source.Task,
         Version = source.Version,
         Payload = new Payload(source.Payload)
     };
 }
        /// <summary>
        /// Implements on begin callback of http module.
        /// </summary>
        public void OnBeginRequest(EventWrittenEventArgs args)
        {
            if (this.telemetryClient == null)
            {
                throw new InvalidOperationException();
            }

            var platformContext = this.ResolvePlatformContext();
            var requestTelemetry = platformContext.ReadOrCreateRequestTelemetryPrivate();

            // NB! Whatever is saved in RequestTelemetry on Begin is not guaranteed to be sent because Begin may not be called; Keep it in context
            // In WCF there will be 2 Begins and 1 End. We need time from the first one
            if (requestTelemetry.StartTime == DateTimeOffset.MinValue)
            {
                requestTelemetry.Start();
            }
        }
        protected override void OnEventWritten(EventWrittenEventArgs eventSourceEvent)
        {
            var metadata = new EventMetaData
            {
                Keywords = (long)eventSourceEvent.Keywords,
                MessageFormat = eventSourceEvent.Message,
                EventId = eventSourceEvent.EventId,
                Level = eventSourceEvent.Level
            };

            var traceEvent = new TraceEvent
            {
                MetaData = metadata,
                Payload = eventSourceEvent.Payload != null ? eventSourceEvent.Payload.ToArray() : null
            };

            this.listener.WriteEvent(traceEvent);
        }
예제 #26
0
 /// <summary>
 /// Pass TPL events to our logger.
 /// </summary>
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     // for now, we just log what TPL already publish, later we actually want to manipulate the information
     // and publish that information
     switch (eventData.EventId)
     {
         case EventIdTaskScheduled:
             Logger.Log(FunctionId.TPLTask_TaskScheduled, string.Empty);
             break;
         case EventIdTaskStarted:
             Logger.Log(FunctionId.TPLTask_TaskStarted, string.Empty);
             break;
         case EventIdTaskCompleted:
             Logger.Log(FunctionId.TPLTask_TaskCompleted, string.Empty);
             break;
         default:
             // Ignore the rest
             break;
     }
 }
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            Action<EventWrittenEventArgs> handler;

            if (this.handlers.TryGetValue(eventData.EventId, out handler))
            {
                try
                {
                    handler(eventData);
                }
                catch (ThreadAbortException)
                {
                    WebEventSource.Log.ThreadAbortWarning();
                }
                catch (Exception exc)
                {
                    WebEventSource.Log.HanderFailure(exc.ToInvariantString());
                }
            }
        }
예제 #28
0
 public static ErrorLogEntry MapError(EventWrittenEventArgs source)
 {
     return new ErrorLogEntry
     {
         Created = DateTime.UtcNow,
         EventId = source.EventId,
         EventSource = JsonSerializer.DeserializeObject<EventSource>(JsonSerializer.SerializeObject(source.EventSource)),
         Id = Guid.NewGuid(),
         Opcode = (Opcodes)source.Opcode,
         Keyword = (Keywords)source.Keywords,
         Level = (Levels)source.Level,
         Message = source.Message,
         Task = (Tasks)source.Task,
         Version = source.Version,
         ExceptionType = (string) source.Payload[0],
         ExceptionMessage = (string) source.Payload[1],
         StackTrace = (string) source.Payload[2],
         Payload = new Payload(new[] { source.Payload.Last() })
     };
 }
예제 #29
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            if (eventData != null)
            {
                var logEvent = new LogEvent();

                logEvent.EventLevel = eventData.Level;
                logEvent.EventId = eventData.EventId;

                var payload = eventData.Payload;

                logEvent.LogMessage = payload[0] as string;
                logEvent.ThreadId = (uint)payload[1];
                logEvent.FilePath = payload[2] as string;
                logEvent.LineNumber = (int)payload[3];
                logEvent.ModluleName = payload[4] as string;

                this.LogEvents.Add(logEvent);
            }
        }
예제 #30
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     switch (eventData.Level)
     {
         case EventLevel.Critical:
         case EventLevel.Error:
             Trace.TraceError(_jobTraceListener.GetFormattedMessage(GetFormattedEventLog(eventData), excludeTimestamp: true));
             break;
         case EventLevel.Warning:
             Trace.TraceWarning(_jobTraceListener.GetFormattedMessage(GetFormattedEventLog(eventData), excludeTimestamp: true));
             break;
         case EventLevel.LogAlways:
         case EventLevel.Informational:
             Trace.TraceInformation(_jobTraceListener.GetFormattedMessage(GetFormattedEventLog(eventData), excludeTimestamp: true));
             break;
         case EventLevel.Verbose:
             Trace.WriteLine(_jobTraceListener.GetFormattedMessage(GetFormattedEventLog(eventData), excludeTimestamp: true));
             break;
     }
 }
        protected override void OnEventWritten(EventWrittenEventArgs e)
        {
            var color = ConsoleColor.Gray;

            switch (e.Level)
            {
                case EventLevel.Informational:
                    color = ConsoleColor.White;
                    break;
                case EventLevel.Warning:
                    color = ConsoleColor.Yellow;
                    break;
                case EventLevel.Error:
                case EventLevel.Critical:
                    color = ConsoleColor.Red;
                    break;
            }

            ConsoleManager.PushColor(color);
            Console.WriteLine(e.Payload[0]);
            ConsoleManager.PopColor();
        }
        public static string ToJson(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var names = eventArgs.PayloadNames;
            var count = names.Count;

            using (var sw = new StringWriter())
                using (var jw = new Json.TinyJsonWriter(sw))
                {
                    jw.WriteStartObject();
                    for (int i = 0; i < count; i++)
                    {
                        var name  = names[i];
                        var value = eventArgs.Payload[i];

                        jw.WritePropertyName(name);
                        jw.WriteValue(value);
                    }
                    jw.WriteEndObject();
                    sw.Flush();
                    return(sw.ToString());
                }
        }
        public static string DumpPayload(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var names = eventArgs.GetPayloadNames();

            var sb = new StringBuilder();

            sb.Append("{");
            var count = eventArgs.Payload.Count;

            for (int i = 0; i < count; i++)
            {
                if (i != 0)
                {
                    sb.Append(", ");
                }
                var name  = names[i];
                var value = eventArgs.Payload[i];
                sb.Append(name).Append(": ").Append(value);
            }
            sb.Append("}");

            return(sb.ToString());
        }
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            if (eventData == null)
            {
                throw new ArgumentNullException("eventData");
            }

            if (m_storageFile == null)
            {
                return;
            }

            var lines = new List<string>();
            var line = String.Format(
                CultureInfo.InvariantCulture,
                MessageFormat,
                DateTime.Now,
                eventData.Level,
                eventData.EventId,
                eventData.Payload[0]);
            lines.Add(line);
            WriteToFile(lines);
        }
예제 #35
0
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            switch (eventData.EventName)
            {
                case "LogArray":
                    {
                        string name = (string)eventData.Payload[0];
                        var arrValues = (IEnumerable<int>)eventData.Payload[1];
                        foreach (int arrValue in arrValues)
                        {
                            Console.WriteLine(arrValue);
                        }
                    } break;
                case "LogNode":
                    {
                        string name = (string)eventData.Payload[0];
                        var node = (IDictionary<string, object>)eventData.Payload[1];
                        var nodeName = node["Name"];
                        var nodeID = (int)node["NodeId"];
                        var childrenIDs = (IEnumerable<int>)node["ChildrenIds"];
                        var userValues = DictionaryFromKeyValues(node["UserValues"]);

                    } break;
                case "LogDictionary":
                    {
                        string name = (string)eventData.Payload[0];
                        var keyValues = DictionaryFromKeyValues(eventData.Payload[1]);
                        // Process the Dictionary

                    }
                    break;
            }
            var id = eventData.ActivityId;
            var rid = eventData.RelatedActivityId;
            var rName = eventData.EventName;
            Console.WriteLine("ActivityId: {0}, RelatedActivityId :{1}", id, rid);
        }
        /// <summary>
        /// Called whenever an event has been written by an event source for which the event listener has enabled events.
        /// </summary>
        /// <param name="eventData">The event arguments that describe the event.</param>
        protected override void OnEventWritten(EventWrittenEventArgs eventData)
        {
            if (eventData == null || eventData.Payload == null)
            {
                return;
            }

            try
            {
                switch (eventData.EventId)
                {
                    case BeginExecuteEventId:
                        this.OnBeginExecute(eventData);
                        break;
                    case EndExecuteEventId:
                        this.OnEndExecute(eventData);
                        break;
                }
            }
            catch (Exception exc)
            {
                DependencyCollectorEventSource.Log.CallbackError(0, "FrameworkSqlEventListener.OnEventWritten", exc);
            }
        }
예제 #37
0
 protected internal virtual void OnEventWritten(EventWrittenEventArgs eventData)
 {
 }
예제 #38
0
 internal protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     LogOnEventWritten(eventData);
 }
예제 #39
0
 protected override void OnAlways(EventWrittenEventArgs eventData)
 {
 }
예제 #40
0
 protected override void OnCritical(EventWrittenEventArgs eventData)
 {
 }
예제 #41
0
 public static Guid GetRelatedActivityId(EventWrittenEventArgs args)
 {
     return RelatedActivityIdAccessor(args);
 }
예제 #42
0
 protected override void OnError(EventWrittenEventArgs eventData)
 {
 }
예제 #43
0
 protected override void OnInformational(EventWrittenEventArgs eventData)
 {
 }
예제 #44
0
 protected override void OnVerbose(EventWrittenEventArgs eventData)
 {
 }
        public static string DumpPayloadOrMessage(this System.Diagnostics.Tracing.EventWrittenEventArgs eventArgs)
        {
            var msg = eventArgs.Message;

            return(string.IsNullOrWhiteSpace(msg) ? eventArgs.DumpPayload() : DumpFormattedMessage(eventArgs));
        }
예제 #46
0
 protected override void OnWarning(EventWrittenEventArgs eventData)
 {
 }
예제 #47
0
 protected override void OnEventWritten(EventWrittenEventArgs eventData)
 {
     _eventWritten?.Invoke(eventData);
 }
예제 #48
0
 protected internal abstract void OnEventWritten(EventWrittenEventArgs eventData);