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.
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.
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