-1

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?

Tim
  • 157
  • 1
  • 11
  • _"I don't know if that's could happen on Windows 10 as well"_: for what I know that happens also on Win10. – Marco Feb 10 '20 at 16:05
  • Why don't you try, just as a test, to write the value of %AppData% in a file inside app folder? So you and your customer could take a look and understand where log file gets written. Another note: why don't you write log file in the app folder (maybe in a subfolder)? – Marco Feb 10 '20 at 16:08
  • So you'd propose to look into other user's APPDATA folders? Or maybe even in `C:\Windows\system32\config\systemprofile\AppData\` in case it's running as a system account. Unfortunately, I can't just change the app and send the new version to the user. But maybe I could provide a small test application. I'll add that to the list of workarounds. – Tim Feb 10 '20 at 16:12
  • 1
    I suggest to use `var str = Environment.ExpandEnvironmentVariables("%AppData%");` and then write `str` to a file inside the folder where the app is running. So you can know for sure which is the %AppFolder% when the app is running as admin. – Marco Feb 10 '20 at 16:15
  • There's already a feature request to add a button for accessing the logging folders. Guess this should be worked on next. But currently this isn't an option, so I'm looking for possible causes of such behaviour. – Tim Feb 10 '20 at 16:22
  • 1
    Tim, most probably cause is that AppFolder used for logging is in Administrator folder... there's not much you can do about it if you don't refactor the app... – Marco Feb 10 '20 at 16:28
  • @Marco you were right, ofc. The user in question used a dedicated admin account to run the application and therefore the logs have been placed in that account's APPDATA folder. If you make this an answer, I'll accept it. – Tim Feb 13 '20 at 11:39

1 Answers1

1

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).

Marco
  • 56,740
  • 14
  • 129
  • 152