My asp.net core program needs to collect all the IP which access the website pre-day.
I need to output the IP list to a txt file when a day is over.
Therefore, the program should run a method to save the IP list once per-day.
How should I design it?
In my opinion, I will add a looping task in the startup.cs
and set the Task.Delay
to 24 hours(one day).
Should I do it like this? Thank you.
This is how I implement scheduler task in ASP.Net Core. Please note that you have to know how to use cron epxression.
First add this package in your csproj
Next I will create SceduledProcessor.cs
The ExecuteAsync will be run for our scenario
Please note that we have to implement GetCronExpression method
Next I will implement the service class
Bonus here I small class with predefined value for cron expression you can use it
Finally add this to your Startup.cs