This post is compatible with Windows Azure SDK v1.3 and v1.4
If you are planning to migrate an existing ASP.NET Web Application to Windows Azure, being able to diagnose any issues is a top priority. Windows Azure provides a comprehensive diagnostics system, designed to solve specific cloud computing diagnosis issues such as reporting statistics and errors across multiple instances in a common aggregated way. To take advantage of these diagnosis tools, you must undertake a few steps in your existing application in order to enable them. This post will detail those steps and the basics of how to migrate any Web Application to Azure.
The builds upon my implementation guide and source code is provided at the end of the post.
This post uses a vanilla ASP.NET web application, and details every step needed to make it equivalent to a brand new Azure Web Role in terms of its ability to use Windows Azure Diagnostics. I created the Web Application using File | New | Web Application – yours will be much more complex, but as a ground up approach, this is my vanilla application:
Next we have to create a Windows Azure Project.
Again this is a vanilla Project. Since we already have our source code in the project that we want to migrate, we don’t need to add any Roles to the solution. So click OK without adding any roles as below:
This empty Azure project is now ready for us to add our Web Application to. For reference this is the default empty project’s structure:
Now add the existing Web Application by right clicking on the solution and adding an Existing project, browsing to your project and adding it to the solution:
At this point you’ll notice that there are no Roles in your solution – this means there’s nothing for Azure to do, a Role is a project that will run on Azure. We must tell Visual Studio that the application that we just added is a Role, and to do that we right click on “Roles” and select a “Web Role in Solution”. This allows us to select from the project list that comes up – note that if you can’t see your project in the list, then you may need to migrate the project to being a Web Application first.
Here are the steps you need:
Now if we start this project with Visual Studio, we’ll see the application run. However, we will not see any diagnostics within the Windows Azure Diagnostics framework, as we haven’t configured anything yet. Thus we must begin to configure the Diagnostics framework.
Start by adding a class to your Web Application Project. You can do this at any point of the application as it will be compiled so it’s path is irrelevant. The name is also irrelevant, it is its inheritance hierarchy that is important.
This class you must make inherit from RoleEntryPoint:
As you can see, the RoleEntryPoint class is underlined by Visual Studio, this means in this case that the class isn’t found, because we are missing a reference and a using directive. You can add a reference to Microsoft.WindowsAzure.ServiceRuntime and add a using directive to solve this:
Now we can begin to add our code to configure the Windows Azure Diagnostics framework. This is done using the code from my previous blog. Firstly however, we must override the OnStart method in order to implement the code in the right place:
Now you can put the following code as the OnStart method:
public override bool OnStart()
{
// put in here all the diagnostics setup that we want
// see http://blog.bareweb.eu/2011/01/implementing-azure-diagnostics-with-sdk-v1-3/
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 = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;
roleInstanceDiagnosticManager.SetCurrentConfiguration(config);
// note that a trace statement here will not append to the Windows Azure Diagnostics as there is no
// trace listener set up for RoleEntryPoint.cs
// make sure you have added the trace listener to web.config as per the blog http://blog.bareweb.eu/2011/01/migrating-to-azure-diagnostics-with-v1-3
return base.OnStart();
}
This will again cause a couple of reference errors, so you should add a reference to Microsoft.WindowsAzure.Diagnostics and Microsoft.WindowsAzure.StorageClient.
Your references will look like this once complete:
If you are using System.Diagnostics.Trace, you must also add a piece of configuration into your Web.Config in order to append trace messages to the new Diagnostics framework. If you are using Windows Event Logs, you do not have to do this, but you must adapt the above “OnStart” method to setup the transfer of Event Log details. Information on how to achieve transfer of Event Logs in Windows Azure can be found here.
The Web Config entry is:
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="AzureDiagnostics" type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</listeners>
</trace>
</system.diagnostics>
Once you have completed this, you can then run your application, and any trace messages will be logged to the WADLogsTable in Development Storage:
You can find the source code for this here: Migrate to Windows Azure Diagnostics

















Doesn”t work for me.
I get error here:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Trace.TraceInformation(string.Concat(“Page_Load Default.aspx: “, DateTime.Now));
}
}
}
ERROR:
Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
InnerException:
Not running in a hosted service or the Development Fabric.
This is your project just as it comes. It is launching the development fabric. I have tried yours and Neil Mackenzie”s suggested code and it does not work.
I could use a little help. SDK 1.3 for diagnostics really stinks from my point of view. I hope the rest of it is more stable. I am really sick of the MS guys – with the “Works on my machine” or “can”t replicate the issue” crap. All they have to do is look at the forums to see that there are a bunch of people all with relate issues. I just want it to work.
Thanks for any help.
Larry
[fabric] Role Instance: deployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0
[fabric] Role state Busy
[Diagnostics]: UpdateState(Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorStartupInfo, Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorConfiguration, )
[Diagnostics]: Acquired mutex
[Diagnostics] Information: C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitor
[Diagnostics] Information: C:AzureMicrosoftDiagAzureDiagDiagnosisMigratedApplicaitonDiagnosisMigratedApplicaitonbinDebugDiagnosisMigratedApplicaiton.csxrolesMigrationWebAppdiagnosticsx64monitorMonAgentHost.exe -LocalPath “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitor” -StaticConfigFile “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitorConfigurationmastaticconfig.xml” -ConfigFile “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitorConfigurationmaconfig.xml” -ShutDownEvent WADDM-ShutDown-80e3f80880a843478ad742f6c67774ee -InitializedEvent WADM-StartUp-80e3f80880a843478ad742f6c67774ee -parent 1792 -events
[Diagnostics]: Creating config channel server
[MonAgentHost] Output: Agent will exit when WADDM-ShutDown-80e3f80880a843478ad742f6c67774ee is signaled.
[MonAgentHost] Output: Will signal WADM-StartUp-80e3f80880a843478ad742f6c67774ee after the agent is initialized.
[MonAgentHost] Output: Registered as an event consumer.
[MonAgentHost] Output: Agent will exit when parent process 1792 exits.
[MonAgentHost] Output: Monitoring Agent Started
[Diagnostics]: Starting configuration channel polling
[runtime] Role entrypoint . CALLING OnStart()
[runtime] Role entrypoint . COMPLETED OnStart()
[runtime] Role entrypoint . CALLING Run()
[Diagnostics]: Checking for configuration updates 3/1/2011 12:19:21 AM.
[Diagnostics]: Signalling process restart on event = WADDM-ShutDown-80e3f80880a843478ad742f6c67774ee
[MonAgentHost] Output: Exiting the monitoring agent after the shutdown event was signaled.
[MonAgentHost] Output: Monitoring Agent Stopped
[Diagnostics] Information: Diagnostic process exited with code: 0
[Diagnostics] Information: C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitor
[Diagnostics] Information: C:AzureMicrosoftDiagAzureDiagDiagnosisMigratedApplicaitonDiagnosisMigratedApplicaitonbinDebugDiagnosisMigratedApplicaiton.csxrolesMigrationWebAppdiagnosticsx64monitorMonAgentHost.exe -LocalPath “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitor” -StaticConfigFile “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitorConfigurationmastaticconfig.xml” -ConfigFile “C:UsersLarryAAppDataLocaldftmps0deployment(423)resdeployment(423).DiagnosisMigratedApplicaiton.MigrationWebApp.0directoryDiagnosticStoreMonitorConfigurationmaconfig.xml” -ShutDownEvent WADDM-ShutDown-55ee5cc06c2845139e2a97dfd603ca2e -InitializedEvent WADM-StartUp-55ee5cc06c2845139e2a97dfd603ca2e -parent 1792 -events
[MonAgentHost] Output: Agent will exit when WADDM-ShutDown-55ee5cc06c2845139e2a97dfd603ca2e is signaled.
[MonAgentHost] Output: Will signal WADM-StartUp-55ee5cc06c2845139e2a97dfd603ca2e after the agent is initialized.
[MonAgentHost] Output: Registered as an event consumer.
[MonAgentHost] Output: Agent will exit when parent process 1792 exits.
[MonAgentHost] Output: Monitoring Agent Started
[Diagnostics]: Starting configuration channel polling
[Diagnostics]: Checking for configuration updates 3/1/2011 12:20:24 AM.
Don”t know why this resolved this issue but, stopping the dev-fabric and letting VS2010 start the dev-fabric fixed this particular issue. I suspect that when VS2010 launches the dev-fabric that it runs with admin or elevated privledges.
In any case it works as you describe. Now to actually get something usefull from it which for the past three days has not been productive.
Larry
Hi Larry,
Sorry it didn”t work first time for you – how was it running to start with? Was the role running directly as the startup task, was everything else normal or was DevFabric in some kind of “unusual state”?
Thanks
Andy