Azure 工作者角色跟踪到开发存储
Azure worker role trace to development storage
我很难将 Azure WorkerRole 中的跟踪日志写入本地开发存储(最终目标是部署后的 Azure 存储)。我用谷歌搜索了好几天,一直在寻找很多这样的例子 http://forums.asp.net/t/2041817.aspx?Azure+Getting+Trace+Data+to+Azure+Storage。不幸的是,即使该讨论最近发生在 2015 年 3 月,它仍然引用了一个显然不受支持的解决方案。代码行
DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
使用 DiagnosticMonitor class,显然现在已弃用。我要么没有在谷歌上搜索正确的东西,要么非常缺乏关于如何以 "newest" 支持 table 方式配置跟踪日志的信息。我可以找到很多关于旧 "deprecated" 方式的信息。
这是我目前所拥有的。我的工作者角色的 app.config 定义了此部分:
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
事实上,这是由创建 WorkerRole 的模板自动添加的。我没有对该部分进行任何手动操作。
ServiceConfiguration.csdef 中的 WorkerRole 部分如下所示:
<WorkerRole name="Processor" vmsize="Small">
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
</ConfigurationSettings>
</WorkerRole>
ServiceConfiguration.Local.cscfg 中的相关角色部分如下所示:
<Role name="Processor">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
然后我在我的 WorkerRole 项目的 classes 之一中有一个 Trace 语句,如下所示:
Trace.TraceInformation("Handling event");
与云项目中的 WorkerRole 关联的 diagnostics.wadcfgx 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Verbose" />
<Directories scheduledTransferPeriod="PT1M">
<IISLogs containerName="wad-iis-logfiles" />
<FailedRequestLogs containerName="wad-failedrequestlogs" />
</Directories>
<PerformanceCounters scheduledTransferPeriod="PT1M">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
</PerformanceCounters>
<WindowsEventLog scheduledTransferPeriod="PT1M">
<DataSource name="Application!*" />
</WindowsEventLog>
<CrashDumps dumpType="Full">
<CrashDumpConfiguration processName="WaAppAgent.exe" />
<CrashDumpConfiguration processName="WaIISHost.exe" />
<CrashDumpConfiguration processName="WindowsAzureGuestAgent.exe" />
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
<CrashDumpConfiguration processName="DiagnosticsAgent.exe" />
<CrashDumpConfiguration processName="w3wp.exe" />
</CrashDumps>
<Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
</DiagnosticMonitorConfiguration>
</WadCfg>
<StorageAccount>teststorage</StorageAccount>
</PublicConfig>
<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount name="teststorage" endpoint="https://core.windows.net/" />
</PrivateConfig>
<IsEnabled>true</IsEnabled>
</DiagnosticsConfiguration>
当我 运行 Visual Studio 中的应用程序时,Azure 存储和计算模拟器成功启动。综上所述,我希望转到 Visual Studio 中的服务器资源管理器,将 Azure 节点一直扩展到存储。进入(Development)节点,看到Tables节点下有一个table包含我的跟踪日志,但是那里什么都没有
显然我做错了什么,还没有找到足够清晰的文档,无论是博客还是微软,都解释了如何让它工作。所以在这里我问的是什么看起来比较简单的东西。
您使用的是 SDK 版本 2.5/2.5.1,它不支持在模拟器中进行诊断。请参阅此 link 以了解重大更改:https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx#BKMK_breaking。从这个 link:
Diagnostics logs are not collected in the Azure compute emulator – For
projects that target the Azure SDK version 2.5, the Azure compute
emulator no longer supports the collection of diagnostics logs,
including performance counters, infrastructure logs, IIS logs, and
event logs. In addition, logs are no longer stored in Azure storage or
development storage. You can continue to view application logs in the
Visual Studio Output window or the compute emulator. This only affects
projects that target Azure SDK version 2.5; projects that continue to
target Azure SDK 2.4 are not affected.
所以,从今天开始,您的选择是:
- 将您的项目定位为使用 SDK 版本 2.4。
- 只在云中进行测试。
- 等待下一个 SDK 版本,希望这个问题能在那里得到解决。
我很难将 Azure WorkerRole 中的跟踪日志写入本地开发存储(最终目标是部署后的 Azure 存储)。我用谷歌搜索了好几天,一直在寻找很多这样的例子 http://forums.asp.net/t/2041817.aspx?Azure+Getting+Trace+Data+to+Azure+Storage。不幸的是,即使该讨论最近发生在 2015 年 3 月,它仍然引用了一个显然不受支持的解决方案。代码行
DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
使用 DiagnosticMonitor class,显然现在已弃用。我要么没有在谷歌上搜索正确的东西,要么非常缺乏关于如何以 "newest" 支持 table 方式配置跟踪日志的信息。我可以找到很多关于旧 "deprecated" 方式的信息。
这是我目前所拥有的。我的工作者角色的 app.config 定义了此部分:
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
事实上,这是由创建 WorkerRole 的模板自动添加的。我没有对该部分进行任何手动操作。
ServiceConfiguration.csdef 中的 WorkerRole 部分如下所示:
<WorkerRole name="Processor" vmsize="Small">
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
</ConfigurationSettings>
</WorkerRole>
ServiceConfiguration.Local.cscfg 中的相关角色部分如下所示:
<Role name="Processor">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
然后我在我的 WorkerRole 项目的 classes 之一中有一个 Trace 语句,如下所示:
Trace.TraceInformation("Handling event");
与云项目中的 WorkerRole 关联的 diagnostics.wadcfgx 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Verbose" />
<Directories scheduledTransferPeriod="PT1M">
<IISLogs containerName="wad-iis-logfiles" />
<FailedRequestLogs containerName="wad-failedrequestlogs" />
</Directories>
<PerformanceCounters scheduledTransferPeriod="PT1M">
<PerformanceCounterConfiguration counterSpecifier="\Memory\Available MBytes" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\ISAPI Extension Requests/sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Web Service(_Total)\Bytes Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Requests/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET Applications(__Total__)\Errors Total/Sec" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Queued" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\ASP.NET\Requests Rejected" sampleRate="PT3M" />
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT3M" />
</PerformanceCounters>
<WindowsEventLog scheduledTransferPeriod="PT1M">
<DataSource name="Application!*" />
</WindowsEventLog>
<CrashDumps dumpType="Full">
<CrashDumpConfiguration processName="WaAppAgent.exe" />
<CrashDumpConfiguration processName="WaIISHost.exe" />
<CrashDumpConfiguration processName="WindowsAzureGuestAgent.exe" />
<CrashDumpConfiguration processName="WaWorkerHost.exe" />
<CrashDumpConfiguration processName="DiagnosticsAgent.exe" />
<CrashDumpConfiguration processName="w3wp.exe" />
</CrashDumps>
<Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
</DiagnosticMonitorConfiguration>
</WadCfg>
<StorageAccount>teststorage</StorageAccount>
</PublicConfig>
<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount name="teststorage" endpoint="https://core.windows.net/" />
</PrivateConfig>
<IsEnabled>true</IsEnabled>
</DiagnosticsConfiguration>
当我 运行 Visual Studio 中的应用程序时,Azure 存储和计算模拟器成功启动。综上所述,我希望转到 Visual Studio 中的服务器资源管理器,将 Azure 节点一直扩展到存储。进入(Development)节点,看到Tables节点下有一个table包含我的跟踪日志,但是那里什么都没有
显然我做错了什么,还没有找到足够清晰的文档,无论是博客还是微软,都解释了如何让它工作。所以在这里我问的是什么看起来比较简单的东西。
您使用的是 SDK 版本 2.5/2.5.1,它不支持在模拟器中进行诊断。请参阅此 link 以了解重大更改:https://msdn.microsoft.com/en-us/library/azure/dn873976.aspx#BKMK_breaking。从这个 link:
Diagnostics logs are not collected in the Azure compute emulator – For projects that target the Azure SDK version 2.5, the Azure compute emulator no longer supports the collection of diagnostics logs, including performance counters, infrastructure logs, IIS logs, and event logs. In addition, logs are no longer stored in Azure storage or development storage. You can continue to view application logs in the Visual Studio Output window or the compute emulator. This only affects projects that target Azure SDK version 2.5; projects that continue to target Azure SDK 2.4 are not affected.
所以,从今天开始,您的选择是:
- 将您的项目定位为使用 SDK 版本 2.4。
- 只在云中进行测试。
- 等待下一个 SDK 版本,希望这个问题能在那里得到解决。