4

I have a TraceManager class that basically calls the TraceEvent method from the System.Diagnostics.TraceSource class.

TraceSource source = new TraceSource("MyTraceSource");
void TraceInternal(TraceEventType eventType, string message)
{
    if (source != null)
    {
        try
        {
            source.TraceEvent(eventType, (int)eventType, message);
        }
        catch (SecurityException)
        {
            //Cannot access to file listener or cannot have
            //privileges to write in event log
            //do not propagete this :-(
        }
    }
}

public void TraceError(string message)
{
    if (String.IsNullOrEmpty(message))
        throw new ArgumentNullException("message", Messages.exception_InvalidTraceMessage);

    TraceInternal(TraceEventType.Error, message);
}

So, for tracing an error I call the TraceError method.

Well, this is the code I use in my WebRole OnStart method:

DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
TimeSpan transferPeriod = TimeSpan.FromMinutes(1.0);

dmc.Logs.ScheduledTransferPeriod = transferPeriod;
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", dmc);

This is my configuration in my web.config:

<system.diagnostics>
  <sources>
    <source name="MyTraceSource" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </source>
  </sources>
  <switches>
    <add name="sourceSwitch" value="Verbose"/>
  </switches>
</system.diagnostics>

And these are my configuration settings for my WebRole:

<ConfigurationSettings>
  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=ValidAcountName;AccountKey=ValidAcountKey" />
</ConfigurationSettings>

And finaly I have the Diagnostics Import in my ServiceDefinition:

<Imports>
  <Import moduleName="Diagnostics" />
</Imports>

When I run my application from Visual Studio under the Azure Emulators it works fine. Even I can change my ConfigurationSettings for saving my logs in the storage emulator or in my cloud storage. But when I deploy it to azure I can't see any Log.

Any ideas?

Paco
  • 41
  • 2
  • I am in the same boat as you, although, I have my logs configured in the diagnostics.wadcfg file located under the Web Role. I've tried initiating it from the WebRole.cs OnStart() method as well, but no luck. The mythical WADLogsTable is nowhere to be found in either case... – Derek Hunziker May 21 '13 at 23:52

2 Answers2

1

Could you check the properties of your Azure project if the following setting is active? If it is, try deactivating it:

enter image description here

Reference: http://michaelcollier.wordpress.com/2012/04/02/where-is-my-windows-azure-diagnostics-data/

Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • Thanks Sandrino for your answer. I have that setting unchecked. – Paco May 31 '12 at 07:09
  • Where are you calling the trace method? In your WebRole.cs or in your actual web application? – Sandrino Di Mattia May 31 '12 at 09:57
  • I've read in WebRole you need to add a listener because it's not the same that in the web application. So I tried this: – Paco May 31 '12 at 16:09
  • ` System.Diagnostics.Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener()); System.Diagnostics.Trace.TraceInformation("In OnStart");` – Paco May 31 '12 at 16:10
0

Have you confirmed that you're defining the TRACE constant when you're building the application? If you have a custom build script, is it possible this constant isn't being defined?

That would prevent the Trace statements from being logged.

Alasdair Ross
  • 370
  • 3
  • 9