Question

I've got an app that I've deployed with Azure, and I am trying to get plain vanilla Tracing working

I've gone through all of these articles: https://stackoverflow.com/search?q=diagnosticmonitortracelistener

Here's my role entry point:

public class WebRole :RoleEntryPoint {
    public override bool OnStart() {
        if (RoleEnvironment.IsAvailable) {
            LocalResource localResource = RoleEnvironment.GetLocalResource("MyCustomLogs");
            DirectoryConfiguration dirConfig = new DirectoryConfiguration();
            dirConfig.Container = "diagnostics-mycustomlogs-container";
            dirConfig.DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes;
            dirConfig.Path = localResource.RootPath;
            DiagnosticMonitorConfiguration diagMonitorConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
            diagMonitorConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
            diagMonitorConfig.Directories.DataSources.Add(dirConfig);
            DiagnosticMonitor diagMonitor = DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagMonitorConfig);

            Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
            Trace.AutoFlush = true;
            Trace.WriteLine("Role Starting");
        }
        return base.OnStart();
    }
}

Also put the trace listener in global.asax.cs:

        if (RoleEnvironment.IsAvailable) {
            Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
            Trace.AutoFlush = true;
        }

I've also tried just pasting it directly into web.config

 <trace>
     <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
            Microsoft.WindowsAzure.Diagnostics, 
            Version=1.8.0.0, 
            Culture=neutral, 
            PublicKeyToken=31bf3856ad364e35"
            name="AzureDiagnostics">
            <filter type="" />
</add>

This directory gets created in my Azure VM C:\Resources\Directory\d63aeab4198d458a9c0b1d0f818e4054.CorpQna.Web.MyCustomLogs

This is in my ServiceDefinition.csdef file:

<LocalResources>
  <LocalStorage name="MyCustomLogs" cleanOnRoleRecycle="false" sizeInMB="10" />
</LocalResources>

When I add a TextWriterTraceListener in my local Compute Emulator, it works:

<trace autoflush="true">
  <listeners>
                    <add type="System.Diagnostics.TextWriterTraceListener" name="TextWriter"
                             initializeData="c:\trace.log" />
  </listeners>
</trace>

However, this does not work on Azure. (I suspect permissions?)

I'm at a standstill at this point. No errors anywhere, but no logs either. There's no record of the Blob being created in my Blob Store.

Était-ce utile?

La solution

Doug, you are confusing a few different concepts here:

  1. Diagnostics Tracing to a file
  2. Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener
  3. WAD DirectoryConfiguration

In .NET, diagnostics tracing will write to all of the registered listeners. The Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener is a trace listener which essentially writes to the WADLogsTable table in Azure Storage. Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener does not write to a local file such as your MyCustomLogs folder. The WAD DirectoryConfiguration will upload files, but this really doesn't have anything to do with .NET diagnostics tracing, unless you are also adding a TextWriterTraceListener.

So your code as-is probably works fine, but you are looking in the wrong place for the data. It won't be in a blob coming from the MyCustomLogs folder, but rather in the WADLogsTable table. If you want the tracing to also be in the MyCustomLogs folder then you can add another listener of type TextWriterTraceListener pointing to a file in your MyCustomLogs folder.

Autres conseils

Have you checked that in your service configuration, you are using correct storage account for diagnostic.

By default, it is pointing to local dev storage. you may have to change with valid storage account.

 <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top