Beispiel #1
0
        public IEnumerable <ReadLogLineResult> ReadLines()
        {
            using var reader = new StreamReader(_stream);
            using var csv    = new CsvReader(reader, _csvConfig);

            var lineNumber = 1;

            while (csv.Read())
            {
                ReadLogLineResult result = null;
                try
                {
                    result = new ReadLogLineResult(lineNumber, csv.GetRecord <T>());
                    lineNumber++;
                }
                catch (Exception ex) when(
                    ex is TypeConverterException ||
                    ex is ReaderException)
                {
                    _processingNotificationsCollector?.ReportError($"Error reading CSV record.  {ex.Message}", _filePath, csv.Context.Row, nameof(CsvLogReader <T>));
                }

                if (result != null)
                {
                    yield return(result);
                }
            }
        }
Beispiel #2
0
        private ReadLogLineResult TurnStringIntoNativeJsonLogBaseEvent(ReadLogLineResult originalEvent)
        {
            if (!(originalEvent.LineContent is string lineString))
            {
                _processingNotificationsCollector.ReportError("Can't interpret line as string", _filePath, originalEvent.LineNumber, nameof(NativeJsonLogsReader));
                return(new ReadLogLineResult(originalEvent.LineNumber, null));
            }

            try
            {
                try
                {
                    var deserializedObject = JsonConvert.DeserializeObject <NativeJsonLogsBaseEvent>(lineString, _serializerSettings);
                    return(new ReadLogLineResult(originalEvent.LineNumber, deserializedObject));
                }
                catch (JsonReaderException ex) when(ex.Message.StartsWith(@"Invalid JavaScript property identifier character:"))
                {
                    // Check for and repair properties using an incorrect ',' character as a number decimal separator in unquoted properties
                    var repairedLineString = NumberDecimalSeparatorRepairRegex.Replace(lineString, "$1.$2");
                    var deserializedObject = JsonConvert.DeserializeObject <NativeJsonLogsBaseEvent>(repairedLineString, _serializerSettings);

                    _processingNotificationsCollector.ReportWarning("Invalid Json found and repaired", _filePath, originalEvent.LineNumber, nameof(NativeJsonLogsReader));
                    return(new ReadLogLineResult(originalEvent.LineNumber, deserializedObject));
                }
            }
            catch (JsonException ex)
            {
                _processingNotificationsCollector.ReportError(ex.Message, _filePath, originalEvent.LineNumber, nameof(NativeJsonLogsReader));
                return(new ReadLogLineResult(originalEvent.LineNumber, null));
            }
        }
Beispiel #3
0
 public LogLine(ReadLogLineResult readLogLineResult, LogFileInfo logFileInfo)
 {
     LineNumber   = readLogLineResult.LineNumber;
     LogFileInfo  = logFileInfo;
     LineContents = readLogLineResult.LineContent;
 }