I was trying to enable Microsoft Azure Diagnostics in a MVC 4 web application which is to be hosted in a Windows Azure web role. I enabled diagnostics via web role properties page
I put few 'Trace.WriteLine' statements in RoleEntryPoint 'Run' method. After deploying to Azure I don't see 'WADLogTable' being created.
I tried putting the same log statements in one of the MVC controller method, then 'WADLogTable' got created and logs got written to this table, still the 'Trace.WriteLine' in RoleEntryPoint 'Run' method not get logged.
Once we enable Microsoft Azure Diagnostics, the following line will get added to web.config file:
....
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
...
ah, I got a clue, I know web application and RoleEntryPoint methods are running under different processes, see this post for details.
As i mentioned in the above post, I created a an application configuration file with name same as the compiled DLL (with .config extension). i.e. if the name of Web Role DLL is NorthWindWebRole.DLL, then the name of the application configuration file must be 'NorthWindWebRole.dll.config'.
Don't forget to set 'Build Action' property for this file to 'Content' and 'Copy To Output Directory' property to 'Copy Always'.
Added diagnostics listener configuration to this file as below, done!! now i can see logging from role entry methods are working:
<?xml version="1.0"?>
<configuration>
<configSections/>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
</configuration>
No comments:
Post a Comment