All I want to do is append the current date and time to my log file, say:
"export_(Wed_Feb_21_2009_at_1_36_41PM)"
Here is my current config from my app.config
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\export.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message %stackTrace%newline" />
</layout>
</appender>
Is appending the date to my log file possible, or is it one of those things I need to do in code and not config?
RollingFileAppender can roll log files based on size or date or both depending on the setting of the RollingStyle property. When set to Size the log file will be rolled once its size exceeds the MaximumFileSize.
Gets or sets the maximum number of backup files that are kept before the oldest is erased.
You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.
To produce file name like:
log_2013-12-19.txt
make changes
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log_"/>
<param name="RollingStyle" value="Date"/>
<param name="DatePattern" value="yyyy-MM-dd.\tx\t" />
<param name="StaticLogFileName" value="false"/>
</appender>
Please observe param "DatePattern" where .\tx\t makes the file name extension .txt. If you provide .txt instead of .\tx\t, then this would save file name with extension .PxP if the time is PM or .AxA in case of AM. so I used \t to enforce to write character instead of pattern. Time may also be added and what ever time pattern needed.
So, this may be really what Philipp M wanted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With