I want to parse data from a log file, pump it into a database, and then purge the log file.
I could use the FileSystemWatcher component, and monitor the Change event, but the event would be firing non-stop, as the log file is pretty much “constantly” being written to. I don’t want to be opening/closing db connections willy-nilly.
My current instinct is to use a Timer, and then parse/pump/purge the log file every so often (based on time or based on time and size of file).
Is there a common/proven way of handling the scenario (design pattern)?
Update: I see FileSystemWatcher has a NotifyFilter property, with one of the filterables being “Size”; I’m guessing (haven’t found any verification yet) that any time the size of the file changes by 1KB it fires; this would be a reasonable “throttle,” if true…
Not sure if this is a design pattern, but if you control how much you buffer before actually writing to the log file you can minimize the frequency.