我正在开发Azure WorkerRole()。在Compute Emulator控制台中,我看到所有Trace.WriteLine()消息,但只有在OnStart()中生成的消息才会被持久存储到存储中。
我的ServiceConfiguration.Local.csfg有:
<Role name="MyWorkerRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
我的WorkerRole.cs有:
public override void Run() {
Trace.WriteLine("Called from Run(), where does this trace go???", "Information");
// ... SNIP ...
}
public override bool OnStart() {
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);
Trace.WriteLine("This trace appears in WADLogsTable", "Information");
return base.OnStart();
}
答案 0 :(得分:3)
看起来很正确 - 我想知道为什么你什么也看不见。我想知道Start是否会以某种方式忽略您的配置更改。这是我使用的一些代码,它将传输跟踪日志(我知道这有用):
private static void EnableDiagnostics(int transferTime)
{
string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);
DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration();
if (config == null)
{
config = DiagnosticMonitor.GetDefaultInitialConfiguration();
}
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(transferTime);
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;
CrashDumps.EnableCollection(true);
roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
}