Esempio n. 1
0
        public GetLatestWebLogsOutput GetLatestWebLogs()
        {
            var directory = new DirectoryInfo(_appFolders.WebSiteLogsFolder);

            if (!directory.Exists)
            {
                return new GetLatestWebLogsOutput {
                           LatestWebLogLines = new List <string>()
                }
            }
            ;

            var lastLogFile = directory.GetFiles("*.txt", SearchOption.AllDirectories)
                              .OrderByDescending(f => f.LastWriteTime)
                              .FirstOrDefault();

            if (lastLogFile == null)
            {
                return(new GetLatestWebLogsOutput());
            }

            var lines        = AppFileHelper.ReadLines(lastLogFile.FullName).Reverse().Take(1000).ToList();
            var logLineCount = 0;
            var lineCount    = 0;

            foreach (var line in lines)
            {
                if (line.StartsWith("DEBUG") ||
                    line.StartsWith("INFO") ||
                    line.StartsWith("WARN") ||
                    line.StartsWith("ERROR") ||
                    line.StartsWith("FATAL"))
                {
                    logLineCount++;
                }

                lineCount++;

                if (logLineCount == 100)
                {
                    break;
                }
            }

            return(new GetLatestWebLogsOutput
            {
                LatestWebLogLines = lines.Take(lineCount).Reverse().ToList()
            });
        }
Esempio n. 2
0
        public GetLatestWebLogsOutput GetLatestWebLogs()
        {
            var directory   = new DirectoryInfo(_appFolders.WebLogsFolder);
            var lastLogFile = directory.GetFiles("*.txt", SearchOption.AllDirectories)
                              .OrderByDescending(f => f.LastWriteTime)
                              .FirstOrDefault();

            if (lastLogFile == null)
            {
                return(new GetLatestWebLogsOutput());
            }

            var lines = AppFileHelper.ReadLines(lastLogFile.FullName).Reverse().Take(100).Reverse().ToList();

            return(new GetLatestWebLogsOutput
            {
                LatesWebLogLines = lines
            });
        }