Force Log4Net RollingFileAppender for roll

According to the Log4Net documentation , RollingFileAppender will only roll up the log file when a message is logged. I need to enter this file, but import it every day into another database. I cannot use the database application because I need the files and I need to transfer the data from the log file to the database (this is not a direct copy). The problem is that after midnight there is no journal activity, the journal does not roll. The importer is looking for a file of previous days (and I can’t change this code), therefore, if there is no activity and the log does not roll, the importer does not find the file. In any case, to make the magazine roll at midnight without having another thread that wakes up and makes it roll? Can a custom appender do this? I would like to avoid this if possible.

+4
source share
3 answers

Record a Windows service that fires an event immediately after midnight that writes a dummy log entry using the same configuration.

+5
source

You should think about this from the point of view of the question: "What code paths lead to a routine scrolling?". Once you know how this procedure is accomplished, you can decide how to start it.

Can a custom appender do this? Of course, but the code in the application will not work until you go through it to return to the square.

Regarding the question, β€œIn any case, to make the log roll at midnight without having another thread that wakes up and makes it roll?”, I would say that this question is equivalent to β€œIs it possible to get log to roll at midnight without running the code? " I am not trying to laugh at it or insult you, I am just trying to repeat the question in a way that I hope will answer it for you. :-)

The easiest way to solve this problem is to wake up and register to make the file rotate.

+3
source

According to the RollingFileAppender documentation, you can configure it for daily cropping, see this configuration:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="logfile" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value="yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> 
0
source

All Articles