Fix: Use AppData directory for log files to avoid permission errors
Issue: Application crashed when installed in Program Files due to UnauthorizedAccessException when trying to write log files to the installation directory. Changes: - SystemInfo.cs: Updated error logging to use LocalApplicationData/PSG-Oversight - OsqueryService.cs: Added GetLogPath() helper method and updated all log writes to use user's AppData directory instead of current directory - Added try-catch wrappers to silently handle any remaining logging failures All log files now write to: %LOCALAPPDATA%\PSG-Oversight\ This fixes the startup crash reported in Event Viewer when running the installed application. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user