我有一个TraceManager类,基本上从System.Diagnostics.TraceSource类调用TraceEvent方法。Azure跟踪日志在模拟器上工作,但不能在云上工作
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中有诊断导入:
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
当我从Azure模拟器下的Visual Studio运行我的应用程序时,它工作正常。即使我可以更改我的ConfigurationSettings以将我的日志保存在存储模拟器或我的云存储中。但是当我将它部署到天蓝色时,我看不到任何日志。
任何想法?
虽然我与您位于同一条船上,但我在位于Web角色下的diagnostics.wadcfg文件中配置了我的日志。我尝试从WebRole.cs的OnStart()方法启动它,但没有运气。神话般的WADLogsTable无处不在... –