Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running With DiagnosticMonitorTraceListener Outside of Azure Compute Emulator

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>
like image 805
Nariman Avatar asked Jul 20 '11 12:07

Nariman


People also ask

Which emulator supports multiple instances of debug cloud services?

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.

How do I turn off Azure storage emulator?

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.

How do I run Azure storage emulator as an administrator?

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.


1 Answers

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());
    }
}
like image 145
Ivan Fioravanti Avatar answered Oct 12 '22 07:10

Ivan Fioravanti