public static void PopulateLogEvent(this LogOpenSchema logTelemetry,
                                            EventTelemetry eventTelemetry)
        {
            var mapping = OpenSchemaMappings;

            if (eventTelemetry.GetProperty(OpenSchemaProps.UnknownMessage) != null)
            {
                logTelemetry.UnknownMessage = Convert.ToBoolean(eventTelemetry.GetProperty(mapping[OpenSchemaProps.UnknownMessage]));
            }
        }
Esempio n. 2
0
        public IOutputBase ToOutput(EventTelemetry eventTelemetry, string schemaName)
        {
            IOutputBase eventBlock = null;

            // Assume Filter has already been applied!
            if (!string.IsNullOrEmpty(schemaName))
            {
                switch (schemaName)
                {
                case LogTypes.Log:
                    eventBlock = new LogOpenSchema();
                    break;

                case LogTypes.Exceptions:
                    eventBlock = new ExceptionsOpenSchema();
                    break;

                case LogTypes.TimedOperation:
                    eventBlock = new TimedOperationOpenSchema();
                    break;

                default:
                    throw new ArgumentException("Unknown OpenSchema Type");
                }

                Dictionary <string, object> customProperties = new Dictionary <string, object>();
                foreach (string property in eventTelemetry.Properties.Keys)
                {
                    if (property.StartsWith(TelemetryProps.CustomPropertyPrefix))
                    {
                        customProperties.Add(property.Remove(0, TelemetryProps.CustomPropertyPrefix.Length), eventTelemetry.Properties[property]);
                    }
                }

                // BaseEvent Properties
                var baseEvent = eventBlock as BaseOpenSchema;
                baseEvent.PopulateEventBlock(eventTelemetry, customProperties);
                // WithMessage Properties
                var messageEvent = eventBlock as BaseOpenSchemaWithMessage;
                messageEvent?.PopulateMessageEvent(eventTelemetry);

                var logEvent = eventBlock as LogOpenSchema;
                if (logEvent != null)
                {
                    logEvent.PopulateLogEvent(eventTelemetry);
                    return(eventBlock);
                }
                var exceptionEvent = eventBlock as ExceptionsOpenSchema;
                if (exceptionEvent != null)
                {
                    exceptionEvent.PopulateExceptionsEvent(eventTelemetry);
                    return(eventBlock);
                }
                var timedOperationEvent = eventBlock as TimedOperationOpenSchema;
                if (timedOperationEvent != null)
                {
                    timedOperationEvent.PopulateTimedOperationEvent(eventTelemetry);
                    return(eventBlock);
                }
            }

            return(eventBlock);
        }