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?