Logs and records system events to the database.