RoleEntryPoint跟踪调用没有使用云服务2.0 Azure SDK进行记录



Scottgu刚刚发布了2.0 SDK:http://weblogs.asp.net/scottgu/archive/2013/04/30/announcing-the-release-of-windows-azure-sdk-2-0-for-net.aspx

我试着创建一个新的MVC4站点。将其添加到云项目中,并按预期包含了以下诊断设置。

  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>

根据:https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/Windows Azure日志默认开启,

记录从代码发送到跟踪侦听器的跟踪消息(跟踪)监听器必须添加到web中。配置或app.config文件)。日志数据将在预定的transferperiodic转移间隔内转移到存储tableWADLogsTable。

诊断。wadcfg:

<?xml version="1.0" encoding="utf-8"?>
<DiagnosticMonitorConfiguration configurationChangePollInterval="PT1M" overallQuotaInMB="4096" xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
  <DiagnosticInfrastructureLogs />
  <Directories>
    <IISLogs container="wad-iis-logfiles" />
    <CrashDumps container="wad-crash-dumps" />
  </Directories>
  <Logs bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Verbose" />
  <WindowsEventLog bufferQuotaInMB="1024" scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error">
    <DataSource name="Application!*" />
  </WindowsEventLog>
</DiagnosticMonitorConfiguration>

我放置了一个Trace。TraceError在我的global.cs和webrole.cs的启动方法,我只得到一个从global.cs.

我错过了什么,或者它不应该也为WebRole工作?

WebRole.cs运行在与您的应用程序本身不同的进程中,并且您的web.config不影响它。

尝试手动设置Trace Listeners代码:

Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());

或者从这里使用解决方案:

从RoleEntryPoint和您的网站读取配置文件:即使是在Windows Azure中存储配置的首选方式应用程序在servicecconfiguration中。CSCFG文件,有在很多情况下,你可能想使用一个普通的。net配置文件特别是在配置。net系统组件或可重用时框架。特别是当您使用Windows Azure诊断时您需要在.NET中配置DiagnosticMonitorTraceListener配置文件。

创建web角色项目时,Visual Studio会创建一个网络。. net配置的配置文件。当你的网应用程序可以访问这些信息,您的RoleEntryPoint代码不能——因为它没有作为你网站的一部分运行。作为前面提到过,它在一个名为WaIISHost.exe的进程下运行,所以它期望它的配置在一个名为WaIISHost.exe.config的文件中。因此,如果您在web项目中创建一个具有此名称的文件并将"Copy to Output Directory"属性设置为"Copy Always"你会发现RoleEntryPoint可以愉快地阅读这些内容。这是一个在我能想到的唯一情况下,您将有两个。net配置文件在同一个项目!

最新更新