Skip to content

Fix log folder location when using --home-dir - #1766

Open
e-nord wants to merge 1 commit into
LykosAI:mainfrom
e-nord:fix-linux-home-dir-log-path
Open

e-nord wants to merge 1 commit into
LykosAI:mainfrom
e-nord:fix-linux-home-dir-log-path

Conversation

@e-nord

@e-nord e-nord commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

When launched with --home-dir, the NLog file target still wrote to %AppData%/StabilityMatrix/Logs (~/.config/StabilityMatrix/Logs on Linux), but Settings → App Folders → Logs and the exception dialog's "open log zip" read from Compat.AppDataHome/Logs. That folder never got created, so both threw:

DirectoryNotFoundException: Could not find a part of the path '/home/ethan/sm-linux/StabilityMatrix/Logs'.
   at StabilityMatrix.Core.Models.FileInterfaces.DirectoryPath.EnumerateFiles(...)
   at StabilityMatrix.Avalonia.ViewModels.Dialogs.ExceptionViewModel.CreateLogFolderZip()

Changes:

  • App.axaml.cs: build the log file path from Compat.AppDataHome, so logs follow --home-dir. Forward slashes avoid NLog interpreting Windows backslashes inside the layout string. Without an override the location is unchanged.
  • Program.cs: resolve a relative --home-dir with Path.GetFullPath. Otherwise AppDataHome stays relative (e.g. StabilityMatrix/Logs), which then gets passed to the file browser and into file:// URIs.

🤖 Generated with Claude Code

The NLog file target was hardcoded to %AppData%/StabilityMatrix/Logs, while
the Settings "Logs" shortcut and the exception dialog's log zip read from
Compat.AppDataHome/Logs. With --home-dir set, those diverged and the log
folder never existed, throwing DirectoryNotFoundException.

Also resolve a relative --home-dir to a full path so folder-browser calls
and file:// URIs don't receive relative paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mohnjiles mohnjiles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two path-handling edge cases on the current head. The NLog layout case was reproduced on Windows with the pinned NLog 5.3.2; the Unix backslash case is based on static path analysis.

{
Layout = "${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}",
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/Logs/app.log",
FileName = $"{logDir}/app.log",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we escape the literal filesystem path before assigning it to both FileName and ArchiveFileName? These properties parse NLog layout syntax. I reproduced this with the pinned NLog 5.3.2 on Windows: a home directory literally named ${shortdate} wrote app.log and its startup archive under 2026-10-04/Logs, while the literal ${shortdate}/Logs directory was absent. Settings and CreateLogFolderZip() still use the literal path, so this recreates the missing-folder issue for those directory names. SimpleLayout.Escape preserved the literal path in the same probe.

// File logging
// Use Compat.AppDataHome so logs follow --home-dir overrides
// (forward slashes to avoid NLog layout escape parsing of backslashes)
var logDir = Compat.AppDataHome.JoinDir("Logs").FullPath.Replace('\\', '/');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve backslashes on Unix, or limit this separator conversion to Windows? A backslash is a valid literal filename character on Linux/macOS, so a home path such as /tmp/home\name becomes /tmp/home/name here. Settings and log ZIP export retain the original path, leaving them pointed at a different directory from the file target. This is a static path finding, not a native Unix runtime repro. Escaping the literal path for NLog would also avoid the need to rewrite its characters.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants