What is your PI version?
If you are on > 7.3 then you can make use of CBMA. If PI is unable to write the file then the message gets error out and triggers an alert.
In the alert text you can include your key field.
Have a look at the below blog for more details.
Enhancing CBMA Alerts and Message Monitoring with UDS Attributes