Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect log4net log in the User Directory

Tags:

.net

log4net

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

like image 252
serhio Avatar asked Sep 17 '10 13:09

serhio


People also ask

Where does log4net write to?

In your case, the log file will be in bin\Debug\netcoreapp3.

What is RollingFileAppender in log4net?

RollingFileAppender means the system creates a log file based on your filters, this way you can have log files based on dates (one file each day), or get the file splitted into small chunks when it hits certain size.


1 Answers

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.

like image 125
moldovanu Avatar answered Sep 22 '22 05:09

moldovanu