We're using DiagnosticMonitorTraceListener as a general trace listener (primarily for for ASP.NET Health Monitoring) as well as an Enterprise Library 5 listener for exception handling. This works well when running on Azure but it's important that we be able to run the website outside of Azure with minimal changes.
One option is to register it dynamically as follows:
protected void Application_Start()
{
if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
{
System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
System.Diagnostics.Trace.AutoFlush = true;
}
}
This works for ASP.NET Health Monitoring and general uses of System.Diagnosics but not for Enterprise Library where we have the following hard-coded configuration:
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
<add name="Azure Diagnostics Trace Listener" />
</listeners>
</add>
</categorySources>
Left unaddressed, calls to ExceptionPolicy.HandleException will generate:
Not running in a hosted service or the Development Fabric.
To conditionally remove this based on where the app is running, we could use the fluent configuration API for EL5 but would have to rewrite our configuration (it's all or nothing).
We could also use web.config transformations except that, in addition to having 3 different solution configurations already (e.g., dev, staging, production), we would have to introduce a 4th to differentiate between dev-standalone vs. dev-azure.
One last option would be to just create a custom listener that will either route all messages to ** ** (if running on Azure) or do nothing.
Any other suggestions?
FYI, ASP.NET Health Monitoring is configured as follows:
<healthMonitoring enabled="true">
<providers>
<add name="TraceWebProvider" type="System.Web.Management.TraceWebEventProvider" />
</providers>
<rules>
<add name="Application Events"
eventName="Application Lifetime Events"
provider="TraceWebProvider"
profile="Default"
minInstances="1"
maxLimit="Infinite"
minInterval="00:01:00" />
</rules>
</healthMonitoring>
The Azure Compute Emulator enables us to test and debug the Azure Cloud Services in our local environment without deploying the Cloud Service to Azure.
AzureStorageEmulator.exe start: Start the emulator. AzureStorageEmulator.exe stop: Stop the emulator. AzureStorageEmulator.exe status: Get current emulator status. AzureStorageEmulator.exe clear: Delete all data in the emulator.
1. Click Start, point to All Programs, and then click Windows Azure SDK. 2. Right-click on Windows Azure SDK Command Prompt and then click Run as administrator.
You can create a DiagnosticMonitorTraceListener and then add it to the collection of TraceSources for your Category.
Remove Azure Diagnostics Trace Listener from EntLib configuration:
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
</categorySources>
And then use the code below to add it at runtime:
protected void Application_Start()
{
if (Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
{
LogSource logSource;
Logger.Writer.TraceSources.TryGetValue("General", out logSource);
logSource.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With