According to the Log4Net documentation, the RollingFileAppender will only roll the log file when a message is logged. I need to log to this file, but import it every day into another database. I cannot use a database appender because I need the files and I have to translate the data from the log file to the database (it isn't a direct copy). The problem is if there is no log activity after midnight, the log doesn't roll. The importer looks for the previous days file (and I can't change this code), so if there is no activity and the log hasn't rolled, the importer doesn't find the file. Is there anyway to force the log to roll at midnight without having another thread that wakes up and forces it to roll? Could a custom appender do this? I would like to avoid this if possible.
Write a Windows Service that fires an event just after midnight that writes a dummy log entry using the same configuration.
According to the RollingFileAppender documentation (http://logging.apache.org/log4net/release/config-examples.html) you can set it to roll on a daily basis, 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>
You have to think about this from the point of the question "what code paths lead to the rollover routine?". Once you know how that routine is reached you can decide how to trigger it.
Could a custom appender do it? Sure, but no code in the appender will run until you log via it so you're back to square one.
As for the question "Is there anyway to force the log to roll at midnight without having another thread that wakes up and forces it to roll?", I would say that that question is equivalent to "Is it possible to force the log to roll at midnight without any code being run?". I'm not trying to be funny about it, or to insult you, I'm just trying to restate the question in a way which will hopefully answer it for you. :-)
The easiest way to solve this is to have something wake up and log to force the file to rotate.