private IActionResult ShowFileText(string file) { string fileName = null; try { fileName = CompressHelper.GzipDecompress(file); } catch { /* 防止人为修改URL,造成解压缩失败 */ } if (string.IsNullOrEmpty(fileName)) { return(new TextResult("parameter error.")); } string logpath = ClientLogController.GetClientLogPath(); string text = null; string filePath = Path.Combine(logpath, fileName); if (File.Exists(filePath)) { text = File.ReadAllText(filePath, Encoding.UTF8); } else { text = "parameter error."; } return(new TextResult(text)); }
private IActionResult ShowFileList() { Dictionary <string, string> dict = new Dictionary <string, string>(); string logpath = ClientLogController.GetClientLogPath(); string[] allfiles = Directory.GetFiles(logpath, "*.*", SearchOption.TopDirectoryOnly); string prefix = DateTime.Today.ToString("yyyy-MM-dd"); string[] logFiles = (from f in allfiles where f.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) select f).ToArray(); foreach (string file in logFiles) { string key = Path.GetFileName(file); if (key.StartsWith(prefix) == false) // 只显示当天的日志 { continue; } string url = GetLogFileUrl(key); dict[key] = url; } return(PageResult("/Log/List.cshtml", dict)); }