[ONNX] Fix diagnostic log and add unittest (#107158)
As title. Previously message was formatted but mistakenly not logged.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/107158
Approved by: https://github.com/titaiwangms
ghstack dependencies: #106741