I have a program that uses log4net. It logs directly in the exe folder.
Now, when passing to station with Windows > XP (Vista, Seven) I observed that the logs are not a
Example of config.xml
:
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="${USERPROFILE}\MyProgramName\Logs\rolling-log-" />
<appendToFile value="true" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="100KB" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd.'log'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Log opening] " />
<footer value="[Log closing] " />
<conversionPattern value="%date %-5level %logger - %message%newline" />
</layout>
</appender>
remark the ${USERPROFILE}
environment variable.
Yes you can change the default log-file location. In the config change the file value
setting. The following puts the file in the root of C:
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="c:\\log-file.txt"/>
You can even use an Environment Variable, the following uses one called TMP:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="${TMP}\log-file.txt" />
<appendToFile value="true" />
Instead of ${USERPROFILE}
(see answer from moldovanu) you can use ${LOCALAPPDATA}
or ${APPDATA}
. This writes your log files to the the users AppData folder (local or roaming sub folder).