.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

log4net and UAC

My logging in my windows forms project is no longer working. Vista UAC is the problem..

I'm using a simple static logging class that writes to the program's application directory. Can't do that anymore if the program is not run in admin mode. To fix this I've got to write actual code... the Horror!

Where are you writing your logs on vista?
This would be for windows forms, but any suggestions appreciated.
Paul
Wednesday, November 21, 2007
 
 
I write them to the same place that I used to on XP. Note that this issue is not "new" with Vista. You should never have been writing them to the C:\Program Files folder or any folder that a limited user does not have permission to access.

Look at the following folder for a location that is shared by all users:

string commonUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

Or the following folder for just the current user:

string commonUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

One extra problem is that when using the shared folder for all users you can run into problems with access rights because only the user who created a file first can delete it. So there is some default ownership rights that are set on the folder. Just make sure that you test shared logging using more than one user to make sure that you aren't running into this issue.
anon
Wednesday, November 21, 2007
 
 
As anon specified, the application data folder is the best place to write these files to. 

What I generally do is create a folder within there the same name as my application (Application.ProductName).
Greg Send private email
Wednesday, November 21, 2007
 
 
Paul,

And in case you're not using .NET, the corresponding API call is SHGetFolderLocation() with CSIDL_APPDATA.
Ken White Send private email
Friday, November 23, 2007
 
 
ty. I know all this. What I want is a way to do it without a single line of new code. The static logging class I have uses a .config file that holds the file name. I don't know of any macros to specify any system directories in the config file, so it looks like I have to rewrite the logging class to fix this. So instead of the happy little line:

XmlConfigurator.ConfigureAndWatch(new FileInfo(Log4NetConfigFile));

I've got to dump the configurator and do actual log4net coding. Problem is very specific to log4net and I thought someone might have a hidden macro tidbit or something.
Paul
Monday, November 26, 2007
 
 
You can use environment variables in the file value. Use the APPDATA environment variable which points to the user's application path.

<file value="${APPDATA}\log-file.txt" />

Would correspond to "c:\Documents and Settings\<User Name>\Application Data\log-file.txt" on XP and "c:\Users\<User Name>\AppData\Roaming\log-file.txt" on Vista. There are many other environment variables that you can use as well. Just go to the command line and type "set" and take your pick.
not a log4net expert
Monday, November 26, 2007
 
 
That's exactly what I was looking for I will try it, ty.
Paul
Monday, November 26, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz