Where are log4net log files stored?

I have a windows application that writes log files using log4net. The log file path in the app.config file is defined as:

<file type="log4net.Util.PatternString" value="Logs/LogFileName" />. 

I have an msi installation project that installs the above application. I install the application on the development machine, run the installed application and, as expected, writes the log files to the directory, InstallDirectory / Logs /. The Dev machine has Win XP SP3 with all read rights.

But when I install the same on a test machine that has Windows 7, and I'm not sure of the permissions, there is no Logs directory and log files.

In both cases, InstallDirectory is C: \ Program Files \ Dir1 \ Dir2.

While I'm trying to figure out where the files are located on a test machine by adding:

 log4net.Appender.FileAppender rootAppender = (log4net.Appender.FileAppender)((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Appenders[0]; string filename = rootAppender.File; MessageBox.Show(filename); 

to the code, can someone shed some light.

  • Why files may be missing?
  • Does Win 7 have different ways to process new files on an installed Windows disk?
+4
source share
3 answers

As others have said, do not work as an administrator to work around this problem. Write to the folder / file that you have access to.

You can expand the environment variables in your configuration to get special folders:

https://web.archive.org/web/20121226213809/http://www.l4ndash.com/Log4NetMailArchive/tabid/70/forumid/1/postid/16299/view/topic/Default.aspx

(or, as recommended in a remote entry on this subject by Jon Skeet , an article that is a bit more general: Where should I write program data instead of program files? )

Try:

 ${LocalAppData}/MyProgram/Logs/Filename 

Or simply:

 ${AppData}/MyProgram/Logs/Filename 

As for which of these two to choose, I'm not sure what β€œroaming” is, so I don’t know why you prefer AppData or LocalAppData . Probably there is another question :)

+5
source

This is a permissions issue. On Windows 7, standard users cannot write to the Program Files directory. Therefore, if you are not using your application as an administrator, Log4Net cannot create this subdirectory. You will have to either grant write access to someone in the Logs/LogFileName when installing the application, or put the log file in the appropriate folder c:\users\username\Application Data\AppName .

+6
source

On Windows7, you must write to the folder C:\Users\<CurrentUser> . Here you can create the installlog folder.

+1
source

Source: https://habr.com/ru/post/1381437/


All Articles