简体   繁体   English

如何在Azure Automation Runbook中显示详细输出?

[英]How to display verbose output in an Azure Automation Runbook?

According to the documentation , you need to have verbose logging enabled to view verbose output from an Azure runbook. 根据文档 ,您需要启用详细日志记录才能查看Azure Runbook的详细输出。 If you enable this setting it displays all verbose output to the point where the output becomes useless (such at 50 lines for modules imports). 如果启用此设置,它将显示所有详细输出,直到该输出变得无用(例如,模块导入为50行)。 This also doesn't appear to display in the "Output" window of the runbook but only in the logging tab. 这似乎也不会显示在运行手册的“输出”窗口中,而只会显示在日志记录选项卡中。

  • I tried adding the -Verbose switch to a Write-Verbose cmdlet. 我尝试将-Verbose开关添加到Write-Verbose cmdlet。 In normal PowerShell, this will produce verbose output no matter what the $VerbosePreference is set to. 在普通的PowerShell中,无论$VerbosePreference设置为什么,这都会产生冗长的输出。 This would have been a solution to only explicitly printing certain verbose output, but it appears to be 'all or nothing' in runbooks. 这本来是仅显式打印某些详细输出的解决方案,但在运行手册中似乎“全有或全无”。

So I'm stuck with producing massive amounts of verbose output which becomes useless. 因此,我坚持要产生大量的冗长输出,而这些输出变得毫无用处。 If I switch to using Write-Output to display to the output pane, then I have to deal with the fact that Write-Output passes objects to the pipeline, making scripts difficult and hard to manage. 如果切换到使用Write-Output显示到输出窗格,则必须处理Write-Output将对象传递到管道的事实,这使得脚本变得越来越难管理。

Any ideas on how to log properly in Azure Runbooks? 有关如何在Azure Runbook中正确记录的任何想法? I'm getting to the point where I'm thinking writing to a logging file in a remote location (maybe a storage account) might sadly be the best option. 我到了要考虑在远程位置(可能是存储帐户)写入日志文件的地步,这可能是最好的选择。 Seems like there should be a better way to handle this. 似乎应该有更好的方法来处理此问题。

Please correct me if I misunderstood you: 如果我误解了你,请纠正我:

After enable verbose logging from "Logging and tracing" in azure portal, I can control the verbose logging via $VerbosePreference and -verbose . 在azure门户中从“日志记录和跟踪”启用详细日志记录之后,我可以通过$VerbosePreference-verbose来控制详细日志记录。

The code: 编码:

在此处输入图片说明

The output: 输出:

在此处输入图片说明

and you can see that even if I set $VerbosePreference="SilentlyContinue", then I add -verbose to write-verbose, the log still can be output. 并且您可以看到,即使我设置$ VerbosePreference =“ SilentlyContinue”,然后将-verbose添加到write-verbose,日志仍然可以输出。

Regarding "This also doesn't appear to display in the "Output" window of the runbook", it's currently not supported for write-verbose. 关于“这似乎也未显示在运行手册的“输出”窗口中”,目前不支持详细写入。 You can submit a request in the user voice of automation runbook . 您可以使用自动化Runbook用户语音提交请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM