Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Turning on Windows Azure Diagnostics
// Simple approach, usually done in RoleEntryPoint::OnStart - though could be otherwise (even done remotely)
// See full working project at https://github.com/codingoutloud/SimpleWAD
public override bool OnStart()
{
Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
Trace.AutoFlush = true;
Trace.TraceInformation("Error");
// Set up to transfer to blob storage
DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
// if not specified, will use overall quota (which is 4 GB):
// diagnosticConfiguration.Logs.BufferQuotaInMB = 10;
// Add the startup task logs directory, so the startup logs will get transferred to storage
var dirConfig = new DirectoryConfiguration();
dirConfig.Container = "wad-startuplogs-container";
dirConfig.Path = Path.Combine((new DirectoryInfo(".")).FullName, "startuplogs");
Trace.TraceInformation("=> dirConfig.Path = " + dirConfig.Path);
diagnosticConfiguration.Directories.DataSources.Add(dirConfig);
diagnosticConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfiguration);
return base.OnStart();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment