示例#1
0
        /// <summary>
        /// Parse the given log file.
        /// </summary>
        /// <returns>Count of documents that were successfully parsed.</returns>
        public long Parse(LogFileContext logFile)
        {
            long processedDocumentCount = 0;

            using (var reader = new StreamReader(new FileStream(logFile.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                while (!parser.FinishedParsing)
                {
                    // Parse a document.
                    JObject document = parser.ParseLogDocument(reader);
                    if (document != null)
                    {
                        DocumentWriteResult result = writer.Write(document);
                        if (!result.IsSuccessful)
                        {
                            Log.WarnFormat("Failed to write document parsed from file '{0}': {1}", logFile, result.ErrorMessage);
                        }
                        else
                        {
                            processedDocumentCount++;
                        }
                    }
                }
            }

            writer.Shutdown();

            return(processedDocumentCount);
        }
示例#2
0
        /// <summary>
        /// Parse the given log file.
        /// </summary>
        /// <returns>Count of documents that were successfully parsed.</returns>
        public long Parse(LogFileContext logFile)
        {
            long processedDocumentCount = 0;

            using (var reader = new StreamReader(new FileStream(logFile.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                while (!parser.FinishedParsing)
                {
                    // Parse a document.
                    JObject document = parser.ParseLogDocument(reader);
                    if (document != null)
                    {
                        DocumentWriteResult result = writer.Write(document);
                        switch (result.Result)
                        {
                        case DocumentWriteResultType.Failure:
                            Log.WarnFormat("Failed to write document parsed from file '{0}': {1}", logFile, result.ErrorMessage);
                            break;

                        case DocumentWriteResultType.SuccessWithWarning:
                            Log.WarnFormat($"Document from file '{logFile}' processed with warning: {result.ErrorMessage}");
                            break;
                        }

                        processedDocumentCount++;
                    }
                }
            }

            writer.Shutdown();

            return(processedDocumentCount);
        }