Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have application it required logging mechanism .am using log4Net for logging.
my requirements are

1)it should create new log file when i start application (errorlog.txt)
2)it should keep one backup log file (errorlog_prev.txt)


i tried this configuration

<appender name="RollingLogFileCommsAppender" type="log4net.Appender.RollingFileAppender">
     <threshold value="All" />
     <file value="${TMP}\errorlog.txt" />
     <appendToFile value="true" />
     <maxSizeRollBackups value="1" />
     <maximumFileSize value="80MB" />
     <rollingStyle value="Once" />
     <StaticLogFileName value="true"/>
     <PreserveLogFileNameExtension value="true"/>
     <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date %-5level - %message%newline" />
     </layout>
   </appender>



its taking one backup but its doesnt have data

What I have tried:

i searched in google i didnt get correct solution
Posted
Updated 4-Dec-20 2:52am
v3
Comments
[no name] 4-Dec-20 8:47am    
There are any number of ways to "backup" a file that uses fewer lines, and is less obscure, than what you've shown.
Mahesh Alappuzha 4-Dec-20 8:51am    
i need to use log4Net for logging.


CHill60 4-Dec-20 9:02am    
Something to try - change it to take 2 backups - does the 2nd backup contain the data you want? If so then you are backing up the initial (empty) state
Mahesh Alappuzha 4-Dec-20 9:05am    
its working:), but i need only one backup it created 2 backup file.
CHill60 4-Dec-20 9:13am    
Delete the empty one. This will give you your starting point. Change the settings back to take only 1 backup. Next run/day your backup should be overwritten with what is currently in the log

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900