예제 #1
0
파일: EventEntry.cs 프로젝트: Brar/entlib
 /// <summary>
 /// Initializes a new instance of the <see cref="EventEntry" /> class.
 /// </summary>
 /// <param name="sourceId">The source id.</param>
 /// <param name="eventId">The event id.</param>
 /// <param name="formattedMessage">The message.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="timestamp">The timestamp.</param>
 /// <param name="schema">The schema.</param>
 public EventEntry(Guid sourceId, int eventId, string formattedMessage, ReadOnlyCollection<object> payload, DateTimeOffset timestamp, EventSchema schema)
 {
     this.providerId = sourceId;
     this.eventId = eventId;
     this.formattedMessage = formattedMessage;
     this.payload = payload;
     this.timestamp = timestamp;
     this.schema = schema;
 }
        private static IReadOnlyDictionary<string, object> InitializePayload(IList<object> payload, EventSchema schema)
        {
            var payloadDictionary = new Dictionary<string, object>(payload.Count);

            for (int i = 0; i < payload.Count; i++)
            {
                payloadDictionary.Add(string.Format("Payload_{0}", schema.Payload[i]), payload[i]);
            }

            return payloadDictionary;
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventEntry" /> class.
 /// </summary>
 /// <param name="sourceId">The source id.</param>
 /// <param name="eventId">The event id.</param>
 /// <param name="formattedMessage">The message.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="timestamp">The timestamp.</param>
 /// <param name="processId">The process id.</param>
 /// <param name="threadId">The thread id.</param>
 /// <param name="activityId">The activity id.</param>
 /// <param name="relatedActivityId">The related activity id.</param>
 /// <param name="schema">The schema.</param>
 public EventEntry(Guid sourceId, int eventId, string formattedMessage, ReadOnlyCollection<object> payload, DateTimeOffset timestamp, int processId, int threadId, Guid activityId, Guid relatedActivityId, EventSchema schema)
 {
     this.providerId = sourceId;
     this.eventId = eventId;
     this.formattedMessage = formattedMessage;
     this.payload = payload;
     this.timestamp = timestamp;
     this.processId = processId;
     this.threadId = threadId;
     this.activityId = activityId;
     this.relatedActivityId = relatedActivityId;
     this.schema = schema;
 }
        private static bool InitializePayload(CloudEventEntry entity, IList<object> payload, EventSchema schema)
        {
            try
            {
                entity.Payload = new Dictionary<string, object>(payload.Count);

                for (int i = 0; i < payload.Count; i++)
                {
                    entity.Payload.Add(schema.Payload[i], payload[i]);
                }

                return true;
            }
            catch (Exception e)
            {
                SemanticLoggingEventSource.Log.WindowsAzureTableSinkEntityCreationFailed(e.ToString());
                return false;
            }
        }
        private EventEntry CreateTestEntry(EventLevel level = EventLevel.Error)
        {
            var schema = new EventSchema(
                1, Guid.Empty, "Test", level,
                (EventTask)2, "Task",
                (EventOpcode)3, "Opcode",
                (EventKeywords)4, "Keywords",
                5, new[] { "Field1", "Field2", "Field3" }
                );

            var payload = new ReadOnlyCollection<object>(new object[]
            {
                "value1",
                2,
                "value3"
            });

            return new EventEntry(
                Guid.Empty, 1, "Test message",
                payload, DateTimeOffset.Now,
                Guid.Empty, Guid.Empty, schema
                );
        }
예제 #6
0
파일: EventEntry.cs 프로젝트: Brar/entlib
        /// <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, schema);
        }
 internal ProbeEventListener(EventSchema eventSchema = null, EventSourceAnalyzer analyzer = null)
 {
     this.eventSchema = eventSchema;
     this.analyzer = analyzer;
     this.TypeOrderOffset = -1;
 }
        private bool TryInvokeMethod(EventSchema eventSchema, EventSource source, ProbeEventListener listener, out MethodInfo method)
        {
            //// Find the method that matches event id or task name
            method = this.GetMethodFromSchema(source, eventSchema);

            if (method != null)
            {
                try
                {
                    // Call with default values to perform all checks but order
                    ParameterInfo[] parameters = method.GetParameters();
                    object[] defaultValues = parameters.Select(p => p.ParameterType.Default()).ToArray();
                    method.Invoke(source, defaultValues);

                    if (listener.Error == null && !this.ExcludeWriteEventTypeOrder)
                    {
                        // Invoke the method at most N-1 times, where N == params count.
                        for (int i = 0; i < parameters.Length - 1; i++)
                        {
                            listener.TypeOrderOffset = i;
                            defaultValues[i] = parameters[i].ParameterType.NotDefault();
                            method.Invoke(source, defaultValues);
                            if (listener.Error != null)
                            {
                                break;
                            }
                        }
                    }

                    return true;
                }
                catch (ArgumentException e)
                {
                    throw new EventSourceAnalyzerException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.EventSourceAnalyzerMethodCallError, method.Name), e);
                }
            }

            return false;
        }
        private void ProbeEvent(EventSchema eventSchema, EventSource source)
        {
            using (var listener = new ProbeEventListener(eventSchema, this))
            {
                try
                {
                    listener.EnableEvents(source, eventSchema.Level, eventSchema.Keywords);
                    MethodInfo method;
                    if (this.TryInvokeMethod(eventSchema, source, listener, out method))
                    {
                        if (listener.EventData == null)
                        {
                            throw new EventSourceAnalyzerException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.EventSourceAnalyzerMissingWriteEventCallError, method.Name));
                        }

                        if (listener.Error != null)
                        {
                            throw listener.Error;
                        }
                    }
                }
                finally
                {
                    listener.DisableEvents(source);
                }
            }
        }
 private MethodInfo GetMethodFromSchema(EventSource source, EventSchema schema)
 {
     return source.GetType().GetMethods(Bindings).SingleOrDefault(m => this.IsEvent(m, schema.Id)) ??
            source.GetType().GetMethod(schema.TaskName, Bindings);
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventEntry" /> class.
 /// </summary>
 /// <param name="sourceId">The source id.</param>
 /// <param name="eventId">The event id.</param>
 /// <param name="formattedMessage">The message.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="timestamp">The timestamp.</param>
 /// <param name="activityId">The activity id.</param>
 /// <param name="relatedActivityId">The related activity id.</param>
 /// <param name="schema">The schema.</param>
 public EventEntry(Guid sourceId, int eventId, string formattedMessage, ReadOnlyCollection<object> payload, DateTimeOffset timestamp, Guid activityId, Guid relatedActivityId, EventSchema schema)
     : this(sourceId, eventId, formattedMessage, payload, timestamp, 0, 0, activityId, relatedActivityId, schema)
 {
 }