예제 #1
0
        private StdoutLogsResponse GetStdOutFileList(string directoryPath, DateTime startTime, DateTime endTime)
        {
            StdoutLogsResponse res = new StdoutLogsResponse();

            res.StdOutLogs = new List <StdoutLog>();

            try
            {
                DirectoryInfo stdLogFolder = new DirectoryInfo(directoryPath);

                foreach (var file in stdLogFolder.GetFiles())
                {
                    if (file.LastAccessTimeUtc >= startTime && file.LastAccessTimeUtc <= endTime)
                    {
                        StdoutLog stdoutLog = new StdoutLog()
                        {
                            Name = file.Name,
                            Path = file.FullName,
                            LastAccessTimeUtc = file.LastAccessTimeUtc,
                            CreationTimeUtc   = file.CreationTimeUtc
                        };
                        res.StdOutLogs.Add(stdoutLog);
                    }
                }

                res.ExceptionMessage = String.Format("Processed files in {0}", directoryPath);
            }
            catch (Exception ex)
            {
                res.ExceptionMessage = ex.Message;
            }

            return(res);
        }
예제 #2
0
        private async Task <StdoutLogsResponse> GetStdoutLogs(string path, DateTime startTime, DateTime endTime)
        {
            string             homeDirectory = Environment.ExpandEnvironmentVariables(@"%HOME%\site\wwwroot\");
            StdoutLogsResponse res           = new StdoutLogsResponse();

            if (!path.EndsWith(@"\"))
            {
                int idx = path.LastIndexOf('\\');
                path = path.Substring(0, idx);
            }

            string stdLogFilesPath = path.StartsWith(".") ? Path.Combine(homeDirectory, path.Substring(2)) : path;

            //for local testing
            //string stdLogFilesPath = @"d:\temp\netcore\LogFiles";

            if (!String.IsNullOrWhiteSpace(stdLogFilesPath))
            {
                return(await Task.FromResult <StdoutLogsResponse>(GetStdOutFileList(stdLogFilesPath, startTime, endTime)));
            }

            return(res);
        }