Prevent unnecessary FS access when building log templates

Previously, each addon was opening the _log_templates.mako in
append mode. This may have resulted in a race condition that
caused the file to be written in an incomplete state.

This patch ensures that _log_templates.mako is only opened
once at run time.

Attempt to fix #1341

thanks @lyndsysimon for looking this over with me
Merge branch 'hotfix/0.21.23'