Example #1
0
        public async Task <ReadResult> TryReadAsync()
        {
            var result = await _inner.TryReadAsync();

            if (result.LogEvent != null)
            {
                foreach (var enricher in _enrichers)
                {
                    enricher.Enrich(result.LogEvent, null);
                }
            }

            return(result);
        }
Example #2
0
        static async Task <BatchResult> ReadBatchAsync(
            ILogEventReader reader,
            Func <LogEvent, bool> filter,
            int count,
            InvalidDataHandling invalidDataHandling)
        {
            var batch  = new List <LogEvent>();
            var isLast = false;

            do
            {
                try
                {
                    while (batch.Count < count)
                    {
                        var rr = await reader.TryReadAsync();

                        isLast = rr.IsAtEnd;
                        var evt = rr.LogEvent;
                        if (evt == null)
                        {
                            break;
                        }

                        if (filter == null || filter(evt))
                        {
                            batch.Add(evt);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex is JsonReaderException || ex is InvalidDataException)
                    {
                        if (invalidDataHandling == InvalidDataHandling.Ignore)
                        {
                            continue;
                        }
                    }

                    throw;
                }

                return(new BatchResult(batch.ToArray(), isLast));
            } while (true);
        }
        public async Task <ReadResult> TryReadAsync()
        {
            var result = await _inner.TryReadAsync();

            if (result.LogEvent == null)
            {
                return(result);
            }

            var evt = new LogEvent(
                result.LogEvent.Timestamp,
                result.LogEvent.Level,
                result.LogEvent.Exception,
                _messageTemplate,
                result.LogEvent.Properties.Select(kv => LogEventPropertyFactory.SafeCreate(kv.Key, kv.Value)));

            return(new ReadResult(evt, result.IsAtEnd));
        }