You have multiple questions hidden in your post, I'll try to answer them all. But first look at current "solution" and how it works.
External host tries to reach mydomain.com:1234.
Host asks DNS server for IP address of mydomain.com, DNS reply external IP address of the router.
Host send data to external IP address:1234, router receives that and
Example of message is follow:
2021-10-13T14:41:10.866435-07:00 X 156613: X-Switch: .Oct 13 13:40:44 PST: %LINEPROTO-SW1-5-UPDOWN: Line protocol on Interface GigabitEthernet195/1/0/11, changed state to down
Seems that PROGRAMNAME points to the number which is incremented by one with every message, in this specific case 156613:
$template TmplAuth, "/var/...