We use the DiagnosticMonitorTraceListener as a common trace listener (mainly for ASP.NET Health Monitoring ), as well as an Enterprise Library 5 listener to handle exceptions. This works well when working on Azure, but itβs important that we can 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 to monitor the health of ASP.NET and the general use of System.Diagnosics, but not for the 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 without an address, ExceptionPolicy.HandleException calls will throw:
It does not work in a hosting service or in development.
To conditionally delete this based on where the application works, we could use the free configuration API for EL5, but would have to rewrite our configuration (all or nothing).
We could also use the web.config transformations, except that in addition to three different solution configurations (for example, dev, staging, production), we would need to enter 4th place for the separation between dev-standalone and dev-azure.
One of the last options is to simply create a custom listener that will either forward 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>