tags:

views:

19

answers:

2

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 always created, due I suppose to the user privileges and other security stuff...

Could I redirect logs to the user folder? Say

\\Username\MyProgram\Logs

+1  A: 

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" />
Joe R
+1  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]&#13;&#10;" />
        <footer value="[Log closing]&#13;&#10;" />
        <conversionPattern value="%date %-5level %logger - %message%newline" />
    </layout>
</appender>

remark the ${USERPROFILE} environment variable.

moldovanu