How to use DIWOS.CronMonitor
// Install → Configure → Register → Ping
MODULE_STATUS:ACTIVE
01. Install
NUGETReference the package in your .NET project.
Command
$ dotnet add package DIWOS.CronMonitorProject file
<ItemGroup>
<PackageReference Include="DIWOS.CronMonitor" Version="1.0.0" />
</ItemGroup>02. Configure
appsettings.jsonAdd a CronMonitor section to appsettings.json. For one worker use PingWorker; for multiple background services use PingWorkers.
Single worker (PingWorker)
{
"CronMonitor": {
"BaseUrl": "https://cron-monitor.com",
"PingPath": "/api/monitor/ping",
"PingWorker": {
"Token": "MonitorTokenForThisWorker",
"Interval": "00:01:00"
}
}
}Multiple workers (PingWorkers)
{
"CronMonitor": {
"BaseUrl": "https://cron-monitor.com",
"PingPath": "/api/monitor/ping",
"PingWorkers": [
{ "Token": "MonitorTokenForThisWorker", "Interval": "00:01:00" },
{ "Token": "MonitorTokenForAnotherWorker", "Interval": "00:05:00" }
]
}
}03. Register with DI
Program.csRegister the client and options using dependency injection.
using DIWOS.CronMonitor;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCronMonitorClient(builder.Configuration);Or configure options in code:
builder.Services.AddCronMonitorClient(options =>
{
options.BaseUrl = "https://cron-monitor.com";
options.PingPath = "/api/monitor/ping";
});04. Send a ping
BackgroundServiceInject ICronMonitorClient and call PingAsync(token) on your schedule.
using DIWOS.CronMonitor;
public sealed class PingWorker(ICronMonitorClient client) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await client.PingAsync("MonitorTokenForThisWorker", stoppingToken);
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
}
}
}05. Optional ping background service
HostedIf you prefer, register the hosted service that pings on the configured interval.
using DIWOS.CronMonitor;
using DIWOS.CronMonitor.BgServices;
builder.Services.AddCronMonitorClient(builder.Configuration);
builder.Services.AddCronMonitorPingBackgroundService(builder.Configuration);06. Notes
README- •The token is sent as text/plain in the POST body.
- •BaseUrl and PingPath are validated during startup.
- •The client uses HttpClientFactory under the hood.
- •It’s safe to use because request URLs are controlled by your configuration.