using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace FATrace.OEMApp.Utils { public static class LogReader { public static IEnumerable ReadTailLines(string filePath, int lineCount) { if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath)) return Enumerable.Empty(); var lines = new LinkedList(); try { using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using var sr = new StreamReader(fs); string? line; while ((line = sr.ReadLine()) != null) { lines.AddLast(line); if (lines.Count > lineCount) lines.RemoveFirst(); } } catch { return Enumerable.Empty(); } return lines; } public static string GetTodayLogPath() { var baseDir = AppContext.BaseDirectory; var logDir = Path.Combine(baseDir, "logs"); var file = Path.Combine(logDir, DateTime.Now.ToString("yyyy-MM-dd") + ".log"); return file; } } }