Search code examples
c#.netlog4netappdata

Why does my application not write to the user's APPDATA on some machines?


I have made an application running on Windows 10 1809. It needs to be run As Administrator and sometimes with command line parameters. One way to do this, would be to run cmd As Administrator, navigate to the folder and run the app with the corrent parameters. Upon starting it creates a logging folder under %APPDATA%\AppName using the built-in functionality of the logging library.

The app has been developed in C#, .Net 4.6 and uses log4net as the logging library, for which the configuration file states:

<file type="log4net.Util.PatternString" value="${AppData}\\AppName\\FileName.log" />

Now I have one user, claiming this wouldn't work for him. The app does neither create the subdirectory (AppName) nor does it create any log files. Since I can't take a direct look at their machine, I'd like to gather some possible reasons for that (also in order to mitigate such behaviour in the future).

On older Windows operating systems I know that running an app As Administrator would sometimes actually run the app with another user account, the admin account. Then the other user's APPDATA folder would be used. I don't know if this could happen on Windows 10 as well, though.

Could there be some kind of misconfiguration on their side?

Also I can't just add workarounds like a FallbackAppender, since it'd have to be discussed with the client.

What could be reasons for an app being able to write to the calling user's APPDATA folder on one Windows 10 machine, but not on another?


Solution

  • IMHO the cause is that the AppData used for logging is in the Administrator folder (you tell us it's run as administrator).
    There's not much you can do other than refactoring the app to write the log in a shared folder (eg the app folder itself or "%systemdrive%\ProgramData\your-app-name" folder).