I plan on either doing a Windows Service, or using Hangfire (right in my web api), for continuously gathering new security event logs similar to that of the Windows Event Viewer.
Looking for feedback/suggestions on doing it with an event listener.
What would happen if I ran a continuous while loop for the life of the service using the following:
using EventLogWatcher logWatcher = new EventLogWatcher(query);
logWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>((sender, e) => LogWatcher_EventRecordWritten(sender, e, domain));
try
{
while (!token.IsCancellationRequested)
{
logWatcher.Enabled = true;
}
}
...
Would this potentially, ever, lead to a memory leak if it runs constantly, for the life of the service running?
Any recommendations on how this should really be handled, please let me know.
Thanks