@Mayank Jain , thank you for posting this question on Microsoft Q&A.
The 5XX errors are collected by default as Performance Metric for Application Gateway. You can access these using the "Metrics" resource menu in Application Gateway Resource. The Counter name corresponding to 5XX error is "Failed requests"
For more details about this metrics, please see Application Gateway metrics
You may also enable diagnostic logs to save this metrics in Log Analytics Workspace or Storage account for longer retention and analysis. For details, see Diagnostic Logs in Application Gateway.
Hope this helps.
If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.