This "action inside a debug logging statement" pattern is one that has shown up elsewhere in the Razor code, and is the primary reason why I didn't actually go ahead and convert all the log outputs from function calls to blocks - because in the later case, this would not execute your code if I did that, and debug messages were turned off. ;)

It would be nicer to execute the script separately from logging the output.  (Perhaps a separate method that can execute it, handle errors, and provide the logging would avoid duplicate code?)