I see a couple things that could cause the error. There is no semicolon at the end of the let statement and TimeGenerated on the second line is incorrect. It looks like you are referencing custom logs so I can't run it in the demo site to better test. If you are not already, try running the query in the new "Logs" Blade in the Log Analytics portal. Analytics has auto-complete and error indication that may help weed out syntax errors.