Call files + hangupcause

What’s the best strategy for using call files and grabbing the hangupcause for the oubound call leg? I’d like to place outbound calls through my primary sip provider into DID’s of my secondary sip provider and vice versa, saving the hangupcause of each call to both alert me if something is down as well as trending the level of service provided by each provider.

Here’s my thoughts and hoping someone can tell me if I’m on the right track or not:
callfile:
channel: [local channel with /n to keep that channel in the call path to maintain local channel variables]
context, extension, and priority pointing to dialplan
set: [setting local channel variables with # to call and some other data for me]

dialplan:
context, extension, and priority (same as callfile) to place outbound call to # that’s passed in
But not sure where to grab the hangupcause (failed, h, etc)
AGI script to log the hangupcause, # called, and the other data to a database.

I’ve tried various combinations but am currently setup as above but I’m not getting the hangupcause. I’ve also tried invoking the dial app directly from the call file rather than the dialplan (extensions.conf) but couldn’t figure out how to access the hangupcause.

Any assistance would be much appreciated!

thanks,
will