I want to add tracing to my startup tasks. I was trying to enable DiagnosticsMonitorTraceListener in a powershell script that runs before all the actual startup tasks. Code:
Add-Type -Path ./Microsoft.WindowsAzure.Diagnostics.dll
$listener = new-object -type Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener
[System.Diagnostics.Trace]::Listeners.Add($listener)
$credentials = new-object -type Microsoft.WindowsAzure.StorageCredentialsAccountAndKey -argumentlist "ACCOUNT_NAME", "ACCOUNT_KEY"
$dmConfig = Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor]::GetDefaultInitialConfiguration();
$dmConfig.Logs.ScheduledTransferPeriod = [System.TimeSpan]::FromMinutes(1)
[Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor]::Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", $dmConfig)
For some reason my traces like this:
[System.Diagnostics.Trace]::TraceInformation("Starting startup tasks")
never end up transferred to Azure Storage. The script runs without any problem. I know that there is a way to make Azure Diagnostic Infrastructure to copy logs generated by startup tasks but as far as I understand, the DiagnosticMonitor gets started only when a role starts. What if a startup task fail and the role never gets to run - the logs are not persisted.
Please let me know if I'm going the wrong way to solve this. Thanks.
One alternative if you are using Visual Studio Ultimate is to use IntelliTrace. That can look at a lot of things during startup. For external tasks, and things like that, check out:
http://blog.smarx.com/posts/windows-azure-startup-tasks-tips-tricks-and-gotchas
And
http://leastprivilege.com/2011/03/04/logging-output-of-azure-startup-tasks-to-the-event-log/