I have a web role (2 instances) and a worker role (2 instances) both roles use the following configuration
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);
When I add some messages I notice that the worker role logs the same entry twice. Do I have to change something?
Thanks for the notice, I will glady repost my hint here as an answer again:
Some project templates in Visual Studio already register an instance of AzureDiagnosticMonitorTraceListener to the Trace.Listeners Collection. You might want to check if there is such a listener already registered before adding a new one:
if (Trace.Listeners.OfType<AzureDiagnosticMonitorTraceListener>().Count() == 0)
{
Trace.Listeners.Add(new AzureDiagnosticMonitorTraceListener());
}