简体   繁体   中英

Best way to handle error logging in a service that accesses the web for database and web api calls

My service monitors a remote database for new records. If any are found then it contacts a web api with a call for each record. If there's an error during that process some would be short lasting, others may cause a permanent failure eg the api server is down, unreachable or moved etc.

My client workflow is repeated every 25 minutes and errors are logged to windows event log and also to a log file.

If there's errors that appear each loop, should I lengthen the loop time or anything else to prevent lots of errors appearing in the windows event log? Does anybody have experience and can help pls? This is my first try of this sort of thing.

This is probably opinion based. In my experience, you'd try to avoid polluting log files with lot's of errors, given there is only 1 source. It's generally a lot easier to troubleshoot a problem if you have 1 error rather than 100s. In practice this would mean you have to have some logic in your code to determine your actions when an error happens.

Here is a list of techniques that can help you with this:

  • Have an operation timeout
  • Use retries count, eg operation can fail at most N times, eg 3
  • Simplify your logging, ensure only useful stuff gets logged
  • Use error log level, separate INFO, DEBUG, WARNING and ERROR
  • Use real-time log viewers to debug your logging process. Eg baretail or tail -f my_log.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM