By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

Program fails to write out its log file

!NoItAll
100+
P: 296
I have written a program that logs errors it encounters. The logging mechanism is very simple. In a try/catch block I gather up the error message(s) into lines in a list. Loglines is a New List(Of String).

The LogFilename is generated as follows:

Expand|Select|Wrap|Line Numbers
  1. Dim LogFileName as String = Path.Combine(My.Application.Info.DirectoryPath, "MyLogFile.log")
  2.  
So I should be writing the log file in the same folder as the exe.

Then I write out the lines with

Expand|Select|Wrap|Line Numbers
  1. IO.File.WriteAllLines(LogFileName, LogLines)
On my system it runs fine and the log file is there. On an end users system no log file ever appears, even though it is catching errors.
Could this be an issue where the exe needs to be run as an administrator?

Perhaps my.application.info.directorypath is returning something bogus on the end-users sysem...?
Mar 21 '16 #1

✓ answered by !NoItAll

So I did find that, unless the program is being run as an administrator, then it will not have write permission. Unfortunately I get no errors because of the way I was trapping errors.
I modified the code to do a test write to the folder inside a try/catch block and then warn the user that the application needs to run as an administrator. I will work on my installer logic to get the program installed to run as an administrator (if that's even possible).

Share this Question
Share on Google+
3 Replies


100+
P: 299
You could just make the end user the owner with full control over the folder that the application is being run from. I tested that method and was able to reproduce your exact situation.
Mar 21 '16 #2

!NoItAll
100+
P: 296
Thanks Luk3r!
Do I do that in my code, or installer? This is a commercial program so I don't have individual access to users machines.
Mar 21 '16 #3

!NoItAll
100+
P: 296
So I did find that, unless the program is being run as an administrator, then it will not have write permission. Unfortunately I get no errors because of the way I was trapping errors.
I modified the code to do a test write to the folder inside a try/catch block and then warn the user that the application needs to run as an administrator. I will work on my installer logic to get the program installed to run as an administrator (if that's even possible).
Mar 24 '16 #4

Post your reply

Sign in to post your reply or Sign up for a free account.