I’ve been using Windows Azure to host a Worker Role in a Cloud Service for an in-development version of my new app, Steam Community Viewer. This service will allow users to be notified of when their friends come online or start playing a game through Windows 8 Toast Notifications. Additionally, it will push updates to Live Tiles for new Steam deals.
During my tests, I tried to turn diagnostics on, but failed to save them to a permanent storage because the table that gets created when you enable basic logging wasn’t actually being created! Windows Azure Basic Logs will be saved in Azure Storage Tables under “WADLogsTable” based on a logging level (error, critical, verbose, etc…). This table is supposed to be automatically created when the service is uploaded and deployed with tracing enabled. If you find that the official Windows Azure documentation on using diagnostics is not helping you with this task, try the code below in your service OnStart() overload.
// instantiate and add a new diagnostic monitor trace listener // before doing this, you should make sure no listeners are defined in your web.config or app.config var tempListener = new DiagnosticMonitorTraceListener(); Trace.Listeners.Add(tempListener); // creates a diagnostic manager instance based on an azure storage account // before doing this, setup a storage account using the azure web portal string connectionStringName = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"; var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(connectionStringName)); var roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); // setup the basic logging configuration options // ScheduledTransferPeriod is how often the trace log is copied to the storage account tables // ScheduledTransferLogLevelFilter is the filter on the messages to copy // BufferQuotaInMB is how much space is available to the local buffer (when limit is reached, old data is purged) var config = roleInstanceDiagnosticManager.GetCurrentConfiguration(); config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0); config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; config.Logs.BufferQuotaInMB = 5; // setup the windows event log configuration options // adds the System and Application level windows event logs to the sources // other options are the same as the basic logging config.WindowsEventLog.DataSources.Add("System!*"); config.WindowsEventLog.DataSources.Add("Application!*"); config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0); config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Undefined; roleInstanceDiagnosticManager.SetCurrentConfiguration(config);