Partilhar via


CrashDumps.EnableCollectionToDirectory Method (String, Boolean)

 

Enables collection mini crash dumps or full crash dumps for a role instance to the specified directory.

Namespace:   Microsoft.WindowsAzure.Diagnostics
Assembly:  Microsoft.WindowsAzure.Diagnostics (in Microsoft.WindowsAzure.Diagnostics.dll)

Syntax

public static void EnableCollectionToDirectory(
    string directory,
    bool enableFullDumps
)
public:
static void EnableCollectionToDirectory(
    String^ directory,
    bool enableFullDumps
)
static member EnableCollectionToDirectory : 
        directory:string *
        enableFullDumps:bool -> unit
Public Shared Sub EnableCollectionToDirectory (
    directory As String,
    enableFullDumps As Boolean
)

Parameters

Remarks

When you enable collection of crash dumps, the resulting data is written locally to the specified directory.

When crash dump data is transferred to persistent storage, it is stored to the wad-crash-dumps Blob container. You can specify the transfer interval of the specified directory by setting the ScheduledTransferPeriod property of Directories.

Example

You can create a local resource for your hosted service by adding a LocalResources element to the ServiceDefinition.csdef file. For example, the following sample creates a local resource called MyCustomCrashDumpsLocation:

ServiceDefinition.csdef

<ServiceDefinition name="MyServiceName" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole1" vmsize="Small"> 
   <LocalResources>
      <LocalStorage name="MyCustomCrashDumpsLocation" sizeInMB="1024" cleanOnRoleRecycle="false" />
   </LocalResources>
</WebRole>
</ServiceDefinition>

The following code snippet creates a DiagnosticMonitorConfiguration object, enables full crash dump collection to the MyCustomCrashDumpsLocation resource, adds the path to the list of directories that are monitored for diagnostic data, and sets a transfer interval of 30 minutes.

WorkerRole.cs

public override bool OnStart()
{
    // Get the default initial configuration for DiagnosticMonitor.
    DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();

    // Create a custom logging path for crash dumps.
    string customCrashDumpsPath = RoleEnvironment.GetLocalResource("MyCustomCrashDumpsLocation").RootPath;

    // Enable full crash dump collection to the custom path.
    CrashDumps.EnableCollectionToDirectory(customCrashDumpsPath, true);

    // Create a new DirectoryConfiguration object.
    DirectoryConfiguration directoryConfiguration = new DirectoryConfiguration();

    // Add the name for the blob container in Windows Azure storage.
    directoryConfiguration.Container = "wad-crash-dumps";

    // Add the directory size quota.
    directoryConfiguration.DirectoryQuotaInMB = RoleEnvironment.GetLocalResource("MyCustomCrashDumpsLocation").MaximumSizeInMegabytes;

    // Add the crash dumps path.
    directoryConfiguration.Path = customCrashDumpsPath;

    // Schedule a transfer period of 30 minutes.
    diagnosticConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(30.0);

    // Add the directoryConfiguration to the Directories collection.
    diagnosticConfiguration.Directories.DataSources.Add(directoryConfiguration);

    // Start the DiagnosticMonitor using the diagnosticConfig and our connection string.
    DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfiguration);

    return base.OnStart();
}

Warning

This API is not supported in Azure SDK versions 2.5 and higher. Instead, use the diagnostics.wadcfg XML configuration file. For more information, see Collect Logging Data by Using Azure Diagnostics.

See Also

CrashDumps Class
Microsoft.WindowsAzure.Diagnostics Namespace

Return to top