diff --git a/LD-SysInfo/Services/OsqueryService.cs b/LD-SysInfo/Services/OsqueryService.cs index 9b4a885..1a7e66b 100644 --- a/LD-SysInfo/Services/OsqueryService.cs +++ b/LD-SysInfo/Services/OsqueryService.cs @@ -9,6 +9,13 @@ namespace LD_SysInfo.Services { public static class OsqueryService { + private static string GetLogPath(string filename) + { + string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PSG-Oversight"); + Directory.CreateDirectory(logDir); + return Path.Combine(logDir, filename); + } + private static string GetOsqueryPath() { var baseDir = AppContext.BaseDirectory; @@ -16,7 +23,11 @@ namespace LD_SysInfo.Services if (!File.Exists(path)) { - File.AppendAllText("osquery_error.log", $"[{DateTime.Now}] ❌ osqueryi.exe not found at {path}\n"); + try + { + File.AppendAllText(GetLogPath("osquery_error.log"), $"[{DateTime.Now}] ❌ osqueryi.exe not found at {path}\n"); + } + catch { /* Silently fail if we can't write logs */ } throw new FileNotFoundException("osqueryi.exe not found", path); } @@ -42,8 +53,12 @@ namespace LD_SysInfo.Services process.WaitForExit(); // Optional debug logging - File.AppendAllText("osquery_debug.log", - $"[{DateTime.Now}] Ran query: {sql}\nOutput length: {output.Length}\n"); + try + { + File.AppendAllText(GetLogPath("osquery_debug.log"), + $"[{DateTime.Now}] Ran query: {sql}\nOutput length: {output.Length}\n"); + } + catch { /* Silently fail if we can't write logs */ } return output; } @@ -69,8 +84,12 @@ namespace LD_SysInfo.Services } catch (Exception ex) { - File.AppendAllText("osquery_error.log", - $"[{DateTime.Now}] ⚠️ JSON parse failed for query '{sql}': {ex.Message}\n"); + try + { + File.AppendAllText(GetLogPath("osquery_error.log"), + $"[{DateTime.Now}] ⚠️ JSON parse failed for query '{sql}': {ex.Message}\n"); + } + catch { /* Silently fail if we can't write logs */ } return new List>(); } } diff --git a/LD-SysInfo/SystemInfo.cs b/LD-SysInfo/SystemInfo.cs index 16329ec..f5c185b 100644 --- a/LD-SysInfo/SystemInfo.cs +++ b/LD-SysInfo/SystemInfo.cs @@ -218,7 +218,17 @@ namespace LD_SysInfo } catch (Exception ex) { - File.AppendAllText("osquery_error.log", $"[{DateTime.Now}] {ex}\n"); + try + { + string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PSG-Oversight"); + Directory.CreateDirectory(logDir); + string logPath = Path.Combine(logDir, "osquery_error.log"); + File.AppendAllText(logPath, $"[{DateTime.Now}] {ex}\n"); + } + catch + { + // Silently fail if we can't write logs + } } return info;