Ejemplo n.º 1
0
        public LogCastDocument Create(LogCastContext context, IEnumerable <ILogDispatchInspector> dispatchInspectors)
        {
            // Many messages will have no properties so we create aggregator only when necessary
            PropertyAccumulator accumulator = null;

            if (!context.Properties.IsEmpty)
            {
                accumulator = new PropertyAccumulator();
                accumulator.AddProperties(context.Properties);
            }

            var summaryBuilder = new ContextSummaryBuilder(context, _detailsFormatter, context.BranchHistory);

            foreach (var message in context.PendingMessages)
            {
                if (message.Properties?.Length > 0)
                {
                    if (accumulator == null)
                    {
                        accumulator = new PropertyAccumulator();
                    }
                    accumulator.AddProperties(message.Properties);
                }

                summaryBuilder.AddMessage(message);
            }

            var summary  = summaryBuilder.Build();
            var document = new LogCastDocument();

            ApplyContext(document, context, summary);

            // Apply properties after context so that client could override standard properties
            accumulator?.Apply(document);

            foreach (var inspector in dispatchInspectors)
            {
                inspector.BeforeSend(document, context);
            }

            document.AddProperty(Property.Durations.Name, Property.Durations.Total,
                                 (int)context.Elapsed.TotalMilliseconds);

            return(document);
        }
Ejemplo n.º 2
0
        public LogCastDocument Create(LogMessage message, IEnumerable <ILogDispatchInspector> dispatchInspectors)
        {
            var document = new LogCastDocument();

            ApplyMessage(document, message);

            if (message.Properties?.Length > 0)
            {
                var accumulator = new PropertyAccumulator();
                accumulator.AddProperties(message.Properties);
                accumulator.Apply(document);
            }

            foreach (var inspector in dispatchInspectors)
            {
                inspector.BeforeSend(document, message);
            }

            return(document);
        }