A Windows Service that periodically checks whether a website is responding, and sends an email alert when the site goes down or comes back up.
- Polls a configured URL on a fixed interval (default 5 minutes).
- Treats any response other than HTTP 200 — or a failure to connect at all — as "down."
- Sends an email when the site's state changes (up→down or down→up), so an ongoing outage produces a single alert rather than one per check.
- Logs activity to the Windows Event Log when running as a service, or to the console when run in interactive mode.
- .NET Framework 4.7.2
- A sending email account. Gmail requires an app password (not your normal password), which means 2-Step Verification must be enabled on the account.
-
Clone the repo.
-
Copy
SiteMonitor/App.config.templatetoSiteMonitor/App.config. -
Fill in your own values in
App.config:Key Description MonitorUrlThe site to check, e.g. https://example.com/SmtpHostSMTP server, e.g. smtp.gmail.comSmtpPortSMTP port, e.g. 587SmtpUserSending account username SmtpPasswordApp password for the sending account EmailFromFrom address EmailToWhere alerts are sent PollIntervalMsCheck interval in milliseconds (300000 = 5 min) App.configis gitignored so your credentials never get committed. Only the template with placeholder values lives in the repo.
Currently it runs as a Windows Service with the steps later in the document, but it runs as a console app so you can see log output and test changes quickly if you edit the csproj and change the Output Type as below:
<OutputType>WinExe</OutputType> <!-- For Windows Service -->
<OutputType>Exe</OutputType> <!-- For debugging in console -->For testing, set PollIntervalMs to something short (e.g. 5000) and point
MonitorUrl at a test endpoint (e.g. https://httpbin.org/status/500 for a
failure) to watch the down/recovered logic fire.
Build the project, then from an Administrator command prompt:
sc create SiteMonitor binPath= "C:\full\path\to\SiteMonitor.exe"
sc start SiteMonitor
Manage it with:
sc stop SiteMonitor
sc delete SiteMonitor
View activity in Event Viewer (eventvwr.msc) under the Application log,
source MySource.
- Credentials are stored in plaintext in
App.config. This keeps them out of source control but is not encryption; secure the machine accordingly.