How do I get log4net to generate log files on startup as a non-admin user?
A process running as a non-administrator user does not have write access to the program files folder. What is the best way to configure log4net to write to a location that a non-admin user has?
Perfectly:
- One config file or config from code will work for all versions of MS Windows supported by .NET.
- MS Windows services support
- Support for log4net version 1.2.0.30714 (we must use this version)
Similar questions:
+2
source to share
1 answer
Why can't you just configure log4net to write to a file in a folder to which you have the appropriate permissions? You do it with FileAppender:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:/path/log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
The above is taken from here . On the same page:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="${TMP}\log-file.txt" />
<appendToFile value="true" />
<encoding value="unicodeFFFE" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
You can use an environment variable to set the file path.
+3
source to share