I use log4net for my desktop application written in c# and deployed using Visual Studio Extension "Microsoft Visual Studio Installer Projects" (MSI-Installer). After installation I do not see the log subfolder defined for log4net.
The TARGETDIR in "Microsoft Visual Studio Installer Projects" is defined as [ProgramFiles64Folder][Manufacturer]\[ProductName]
.
The log4net log file is defined as
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value=".\log\MyApp.log" />
<!-- ... -->
After installing the application via the "Microsoft Visual Studio Installer Projects"-created setup.exe and msi-installer I do not see the log-folder in the Windows explorer under Program Files\MyManufacturer\MyProductName although Show hidden files, folders, ... is set.
For testing purposes I added the following code to my application:
// does log file exist and grow ?
string currdir = Directory.GetCurrentDirectory();
MessageBox.Show(currdir, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
string[] sa = File.ReadAllLines(currdir + "\\log\\MyApp.log");
MessageBox.Show(sa.Length.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
// show lines created this year (2019)
string s = "";
for (int i = 0; i < sa.Length; i++)
{
if(sa[i].Contains("2019"))
s = s + sa[i] + "\n";
}
MessageBox.Show(s, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
So, the log file under Program Files\MyManufacturer\MyProductName\log\MyApp.log
can be accessed via the application and I see that it grows!
So the question is: Where is the log subdirectory ? How can I make it visible in the Wndows explorer ? Is this a permission issue ?
Bitness?: Are you sure you are looking in the right folder? Did you check in
Program Files (x86)
to be sure?Virtualization / Data Redirection: I am wondering if you have policies enabled that auto-magically redirect failed writes in secured folders to another writable location? User Account Control: Virtualize file and registry write failures to per-user locations.
Data Redirect / Virtualization Policy Entry:
To find and change this policy, please do as follows (or equivalent by other means):
Windows Key
+ tapR
.%windir%\system32\secpol.msc /s
.OK
or hitEnter
.Local Policies\Security Options
. Look for entry:User Account Control: Virtualize file and registry write failures to per-user locations
.Activated
"?Task Manager & Virtualization: You can see the
virtualization status
of a program by adding theVirtualization column
to the Processes page in Task Manager (in Windows 10 use the Details view - it should say something like UAC-Virtualization there):Where Does It Write?: If this data redirection / virtualization setting is active, the log is redirected to a writable location automatically whilst still showing the original path in your application. Please check under:
%LocalAppData%\VirtualStore
. Procedure:Windows Key
+ tapR
.%LocalAppData%\VirtualStore
.OK
or hitEnter
.Technical Notes: Just for the record. With regards to the test application I used to debug:
File.WriteAllText(@"C:\Program Files\My folder\TestFile.txt", "Test");
(create path first and adjust "Program Files" part to your language)Project
=>Add New Item...
=>Application Manifest File
."Security"
section.Now try to build and run. You should see the application activated for virtualization in the UAC-Virtualization column of Task Manager (screenshot above). Clicking the button should write to
%LocalAppData%\VirtualStore
if the data redirect / virtualization policy is active.Some Links: