How to find Date and Time from Event Viewer and insert it into database table in SQL-Server using C#?
Please suggest me is it possible through like- windows service or console application or windows form or api ?
Loading
How to find Date and Time from Event Viewer and insert it into database table in SQL-Server using C#?
Please suggest me is it possible through like- windows service or console application or windows form or api ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mahesh ChandPosted Jan 6, 2023, 2:02 AM
Answer generated by ChatGPT.
To find the date and time of an event in the Event Viewer using C#, you can use the
EventLogclass from theSystem.Diagnosticsnamespace. This class allows you to read events from event logs, including the system event log, on the local or a remote computer.Here is an example of how you can use the
EventLogclass to retrieve the date and time of an event:Aravind GovindarajPosted Jan 5, 2023, 4:36 PM
Please find the snippet to read the event viewer using C#.
https://stackoverflow.com/questions/3147972/read-event-log-in-c-sharp
It's up to your business use case, which way you want to consume event viewer. My suggestion is to create a separate library to read the event viewer, something like EventCollector which now will consume it from EventViewer, maybe tomorrow you are relaying on a different source. On top of that, you can switch to whichever way you want. may be console/win service/form/API.
hope this helps you