Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task DispatchAsync(TraceRecord record, CancellationToken token)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            if (record.Target != null)
            {
                await record.DispatchAsync(token).ConfigureAwait(false);
            }

            // TODO : Do dispatching in Batches over a separate Task
            var currentRecord = record.Next;

            while (currentRecord != null)
            {
                // Remember that in our map, we only maintain the template of TraceRecord. They don't have full details (only have information on
                // what trace this is, and where should it be dispatched to, when a Record for this template shows up.
                // The TraceRecord object we receive when dispatch is called has all the data inside it. Now that we have dispatched it,
                // if there are more in the list, we go through them one by one, fill the details, and dispatch them.
                // Also note, we don't do a deep copy while dispatching. If the caller needs to keep the object around, they will
                // have to call Clone on it.
                if (currentRecord.Target != null)
                {
                    currentRecord.Level               = record.Level;
                    currentRecord.TracingProcessId    = record.TracingProcessId;
                    currentRecord.ThreadId            = record.ThreadId;
                    currentRecord.TimeStamp           = record.TimeStamp;
                    currentRecord.PropertyValueReader = record.PropertyValueReader;

                    await currentRecord.DispatchAsync(token).ConfigureAwait(false);

                    currentRecord.PropertyValueReader = null;
                }

                currentRecord = currentRecord.Next;
            }
        }