我有一个Web角色(2个实例)和一个辅助角色(2个实例),这两个角色都使用以下配置
DiagnosticMonitorTraceListener tmpListener = new DiagnosticMonitorTraceListener();
System.Diagnostics.Trace.Listeners.Add(tmpListener);
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();
config.Logs.BufferQuotaInMB = 500;
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Information;
roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
当我添加一些消息时,我注意到worker角色记录了两次相同的条目。我需要改变什么吗?
答案 0 :(得分:3)
感谢您的通知,我将再次将我的提示重新发布作为答案:
Visual Studio中的某些项目模板已将一个AzureDiagnosticMonitorTraceListener实例注册到Trace.Listeners集合。在添加新的侦听器之前,您可能想要检查是否已经注册了这样的侦听器:
if (Trace.Listeners.OfType<AzureDiagnosticMonitorTraceListener>().Count() == 0)
{
Trace.Listeners.Add(new AzureDiagnosticMonitorTraceListener());
}