2012-01-19 24 views
1

我想为我的启动任务添加跟踪。我试图在所有实际启动任务之前运行的powershell脚本中启用DiagnosticsMonitorTraceListener。代码:在启动任务运行之前启用DiagnosticsMonitorTraceListnener

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) 

出于某种原因,我的痕迹这样的:

[System.Diagnostics.Trace]::TraceInformation("Starting startup tasks") 

永不结束转移到Azure存储。脚本运行没有任何问题。 我知道有一种方法可以让Azure诊断基础结构复制启动任务生成的日志,但据我了解,DiagnosticMonitor只有在角色启动时才会启动。如果启动任务失败并且角色永远无法运行 - 日志不会保留。

请让我知道,如果我错误的方式来解决这个问题。谢谢。

回答

0

如果您使用Visual Studio Ultimate,另一种方法是使用IntelliTrace。这可以在启动过程中查看很多事情。对于外部的任务,事情就是这样的,请上网:

http://blog.smarx.com/posts/windows-azure-startup-tasks-tips-tricks-and-gotchas

而且

http://leastprivilege.com/2011/03/04/logging-output-of-azure-startup-tasks-to-the-event-log/

+0

启动任务远程机器上运行,而我可能无法访问,e.g,生产服务器。如果我决定写入事件日志,那么当其中一个启动任务失败时(DiagnosticMonitor永远不会启动),我仍然需要编写自定义逻辑,以便将事件日志保留在Azure存储中。 – Janusz

相关问题