BatchGuy.App.X264Log.Services.X264LogParserService.GetLogs C# (CSharp) Method

GetLogs() public method

public GetLogs ( ) : string
return string
        public string GetLogs()
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                sb.AppendLine("[pre]");
                sb.AppendLine("[quote]");
                sb.AppendLine("[b]x264 Logs[/b]");
                sb.AppendLine();

                if (_x264LogFileSerttings.BBCodeHiddenAroundLogs)
                    sb.AppendLine("[hide]");

                foreach (X264LogFile logFile in _logFiles.OrderBy(l => l.FileNameOnly))
                {
                    if (_x264LogFileSerttings.BBCodeBoldLogFileName)
                        sb.AppendLine(string.Format("[b]{0}[/b]", logFile.FileNameOnly));
                    else
                        sb.AppendLine(string.Format("{0}", logFile.FileNameOnly));

                    sb.AppendLine();

                    using (StreamReader sw = new StreamReader(logFile.FilePath))
                    {
                        while (true)
                        {
                            string line = sw.ReadLine();
                            if (line != null)
                            {
                                EnumX264LogLineItemType lineItemType = _x264LogLineItemIdentifierService.GetLineItemType(line);
                                if (lineItemType != EnumX264LogLineItemType.None)
                                {
                                    sb.AppendLine(line);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        sb.AppendLine();
                    }
                }

                if (_x264LogFileSerttings.BBCodeHiddenAroundLogs)
                    sb.AppendLine("[/hide]");

                sb.AppendLine("[/quote]");
                sb.AppendLine("[/pre]");
            }
            catch (Exception ex)
            {
                _log.ErrorFormat(Program.GetLogErrorFormat(), ex.Message, ex.StackTrace, MethodBase.GetCurrentMethod().Name);
                _errors.Add(new Error() { Description = string.Format("Error: {0}", ex.Message) });
            }

            _logs = sb.ToString();

            return sb.ToString();
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            //line item identifier service used to identify the line type read from log file
            IX264LogLineItemIdentifierService x264LogLineItemIdentifierService = new X264LogLineItemIdentifierService();

            //x264 log file settings
            X264LogFileSettings x264LogFileSerttings = new X264LogFileSettings() { BBCodeBoldLogFileName = true, BBCodeHiddenAroundLogs = true };

            //log files
            List<X264LogFile> logFiles = new List<X264LogFile>() {
                new X264LogFile() { FileNameOnly = "Les Revenants S02E01 The Child 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E01 The Child 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() { FileNameOnly = "Les Revenants S02E02 Milan 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E02 Milan 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E03 Morgane 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E03 Morgane 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E04 Virgil 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E04 Virgil 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E05 Madame Costa 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E05 Madame Costa 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E06 Esther 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E06 Esther 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E07 Étienne 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E07 Étienne 720p BluRay DTS x264.mkv.x264.log" },
                new X264LogFile() {  FileNameOnly = "Les Revenants S02E08 Les Revenants 720p BluRay DTS x264.mkv.x264.log", FilePath = @"C:\temp\My Encodes\Blu-ray\Les Revenants S02E08 Les Revenants 720p BluRay DTS x264.mkv.x264.log" }};

            //parser service
            IX264LogParserService parserService = new X264LogParserService(x264LogLineItemIdentifierService, x264LogFileSerttings, logFiles);

            Stopwatch watch = new Stopwatch();
            watch.Start();

            //get log text
            string logs = parserService.GetLogs();

            if (parserService.Errors.Count() == 0)
            {
                System.Console.WriteLine(logs);
            }
            else
            {
                System.Console.WriteLine(parserService.Errors[0].Description);
            }
            watch.Stop();

            System.Console.WriteLine(string.Format("The process took {0} seconds", watch.Elapsed.TotalSeconds.ToString()));

            System.Console.ReadLine();
        }