Adding a system_log.write to every automation with Trigger info - How to Standardize?

I’ve added the following action to each automation to write a message to the log when the automation triggers. It includes all the trigger data:

    - service: system_log.write
      data:
        message: >
              {% set data = namespace(print_out="TRIGGER ToD Actions for MBR Lights:",pr_value="") %}
              {% for key,value in trigger.items() %}
                {% if value is not none and value is not mapping and key not in ['id','idx'] %}
                  {% if value is not string %} {% set data.pr_value = value|string %}
                  {% else %}                   {% set data.pr_value = value %}
                  {% endif %}
                  {% set data.print_out = data.print_out + "\n\t\t\t\t" + key + ":\t\t" + data.pr_value %}
                {% endif %}
              {% endfor %}
              {% set data.print_out = data.print_out + "\n" %}
              {{ data.print_out }}
        logger: AUTOMATION TRIGGERED
        level: error

The issue is that as I tinker with my automations, I occasionally add some information to the message. Which means if I want to maintain consistency, then I have to make the change to all the automations.

My question: Is there a way to do this with an include file? Something like:

message: !include log_action_for_automations.message

where log_action_for_automations.message is:

{% set data = namespace(print_out=this.attributes.friendly_name + ":",pr_value="") %}
{% for key,value in trigger.items() %}
  {% if value is not none and value is not mapping and key not in ['id','idx'] %}
    {% if value is not string %} {% set data.pr_value = value|string %}
    {% else %}                   {% set data.pr_value = value %}
    {% endif %}
    {% set data.print_out = data.print_out + "\n\t\t\t\t" + key + ":\t\t" + data.pr_value %}
  {% endif %}
{% endfor %}
{% set data.print_out = data.print_out + "\n" %}
{{ data.print_out }}

This throws the following error to the log when I reload automation:

2024-08-28 13:18:45.502 ERROR (SyncWorker_5) [homeassistant.util.yaml.loader] while scanning for the next token
found character '%' that cannot start any token
  in "/config/config-include-files/automations/log_action_for_automations.message", line 1, column 2
2024-08-28 13:18:45.507 ERROR (MainThread) [homeassistant.components.automation] while scanning for the next token
found character '%' that cannot start any token
  in "config-include-files/automations/log_action_for_automations.message", line 1, column 2

My guess us that one of the errors is when HA is loading the automations, which I do with an include that is in configuration.yaml.

automation: !include_dir_merge_list config-include-files/automations/

and the other error is when it loads the actual automation. But that’s a guess. Can anyone suggest the proper way to do this? Or a better way overall to have a consistent message written to the logs when an automation triggers? Thanks!!