Our DMS Software Reengineering Toolkit with its Visual Basic Front End can be used for this.
DMS analyzes the source code using the front end for abstract syntax trees, and then allows you to use arbitrary analysis / transformation for these trees. Many transformation changes can be made by converting the source files to their original state , in which the code is rewritten using "if you see this syntax, replace it with this syntax", using grammar as a way to define abstract placeholders. This makes it easy to write transformations to code using familiar syntax. This generalizes the OP method, which attempts to match token sequences.
The OP problem can be posed as an aspect like rewriting a form:
default domain VisualBasic~VB6; rule function_insert_log_call(a: attributes, t: type, i: IDENTIFIER, p: parameters, s:statements) = function -> function = " \a FUNCTION \i ( \p ) AS \t \s END FUNCTION" -> "\a FUNCTION \i ( \p ) AS \t my_log(\tostring\(\i\)) \s END FUNCTION"; rule subroutine_insert_log_call(a: attributes, i: IDENTIFIER, p: parameters, s:statements) = subroutine -> subroutine = " \a SUB \i ( \p ) \s END SUB" -> " \a SUB \i ( \p ) my_log(\tostring\(\i\)) \s END SUB";
These rewrites are of the form
rule *rulename* ( *patternvars* ) *nonterminal* -> *nonterminal* = " *syntaxpattern* " -> " *syntaxpattern* ";
The given specific rules will recognize headers and function objects regardless of the contents / spaces / comments, since they actually correspond to AST. "..." is the meta-lead, and the external is the syntax of the DMS rule and internally is the syntax of VB6. \ N inside the "..." is the (AST) parameter that must correspond to the grammatical nonterminal N declared in the header as rule. .. n: N .... tostring is a regular meta function (called using meta parens ()) that converts an argument from a node tree to a node tree for a string string.
OP may require more rules than to handle other cases; perhaps he wants to keep a GOSUB call log and / or to capture functional parameters in a log call.
Another answer involves getting a parser generator and, well, defining VB6 to enable parsing. It is important to understand that getting the VB6 syntax right is really difficult; langauge is poorly documented and has some really weirder rules regarding spaces, statements-inside lines and statements across line boundaries. If you do not, you simply cannot parse hundreds of files. We had to define our own grammar (like DMS has for many other languages ).
You can learn more about software / code logging with software transformations here.