Azure跟踪日志在模拟器上工作但不在云上工作

时间:2012-05-30 17:56:05

标签: logging azure cloud trace diagnostics

我有一个TraceManager类,它基本上从System.Diagnostics.TraceSource类调用TraceEvent方法。

TraceSource source = new TraceSource("MyTraceSource");
void TraceInternal(TraceEventType eventType, string message)
{
    if (source != null)
    {
        try
        {
            source.TraceEvent(eventType, (int)eventType, message);
        }
        catch (SecurityException)
        {
            //Cannot access to file listener or cannot have
            //privileges to write in event log
            //do not propagete this :-(
        }
    }
}

public void TraceError(string message)
{
    if (String.IsNullOrEmpty(message))
        throw new ArgumentNullException("message", Messages.exception_InvalidTraceMessage);

    TraceInternal(TraceEventType.Error, message);
}

因此,为了跟踪错误,我调用了TraceError方法。

嗯,这是我在WebRole OnStart方法中使用的代码:

DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
TimeSpan transferPeriod = TimeSpan.FromMinutes(1.0);

dmc.Logs.ScheduledTransferPeriod = transferPeriod;
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", dmc);

这是我在web.config中的配置:

<system.diagnostics>
  <sources>
    <source name="MyTraceSource" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </source>
  </sources>
  <switches>
    <add name="sourceSwitch" value="Verbose"/>
  </switches>
</system.diagnostics>

这些是我的WebRole的配置设置:

<ConfigurationSettings>
  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=ValidAcountName;AccountKey=ValidAcountKey" />
</ConfigurationSettings>

最后,我的ServiceDefinition中有Diagnostics Import:

<Imports>
  <Import moduleName="Diagnostics" />
</Imports>

当我从Azure Emulator下的Visual Studio运行我的应用程序时,它工作正常。甚至我可以更改ConfigurationSettings以将我的日志保存在存储模拟器或我的云存储中。但是当我将它部署到azure时,我看不到任何Log。

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

如果以下设置处于活动状态,您是否可以检查Azure项目的属性?如果是,请尝试停用它:

enter image description here

参考:http://michaelcollier.wordpress.com/2012/04/02/where-is-my-windows-azure-diagnostics-data/

答案 1 :(得分:0)

您是否确认在构建应用程序时正在定义TRACE常量?如果您有自定义构建脚本,是否可能未定义此常量?

这会阻止记录Trace语句。

相关问题