DirectoryConfiguration.Path Property


Gets or sets the absolute path for the local directory to which file-based logs are written.

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

public string Path { get; set; }

Property Value

Type: System.String

Type: System.String

Returns String.

This property specifies the local directory to which a role instance’s DiagnosticMonitor will store file-based diagnostics and logging data. When a scheduled or on-demand transfer is requested, the data in this directory is copied to Blob storage in the cloud and removed from local storage.


If your role instance fails, any local logging data may be deleted. To prevent data loss, transfer data from local storage to persistent storage on a frequent interval.


You use this property by creating a new DirectoryConfiguration object and assigning its Path property value. In this example, we use the GetLocalResource method to get the path for the location of our custom logs:

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

// Add the log path for the role using RoleEnvironment.GetLocalResource().
directoryConfiguration.Path = @".\MyCustomLogs\"

The following code snippet shows the property in the context of remotely updating the diagnostics configuration of each instance in a role. This snippet gets the diagnostics configuration of each instance, creates a new DirectoryConfiguration object, specifies the directory path for our custom logs, adds the configuration to our DiagnosticMonitorConfiguration object, and sets the new configuration.

// Get the connection string. It's recommended that you store the connection string in your web.config or app.config file.
// Use the ConfigurationManager type to retrieve your storage connection string.  You can find the account name and key in
// the Azure classic portal (
//string connectionString = "DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;

// The deployment ID and role name for your application can be obtained from the 
// Azure classic portal ( See your 
// application dashboard under Cloud Services.
string deploymentID = "e2ab8b6667644666ba627bdf6f5e4daa";
string roleName = "WebRole1";

// Get the DeploymentDiagnosticManager object for your deployment.
DeploymentDiagnosticManager diagManager = new DeploymentDiagnosticManager(connectionString, deploymentID);

// Get the RoleInstanceDiagnosticManager objects for each instance of your role.
IEnumerable<RoleInstanceDiagnosticManager> instanceManagers = diagManager.GetRoleInstanceDiagnosticManagersForRole(roleName);

// Iterate through the role instances and update the configuration.
foreach (RoleInstanceDiagnosticManager roleInstance in instanceManagers)
   DiagnosticMonitorConfiguration diagnosticConfiguration = roleInstance.GetCurrentConfiguration();

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

   // Add the name for the blob container in Azure storage.
   directoryConfiguration.Container = "wad-custom-logs";

   // Add the directory size quota.
   directoryConfiguration.DirectoryQuotaInMB = 2048;

   // Add the log path.
   directoryConfiguration.Path = @".\MyCustomLogs\";

   // Add the directoryConfiguration to the Directories collection.

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


The following snippet from a ServiceDefinition.csdef file defines the MyCustomLogs directory.

    <LocalStorage name="MyCustomLogs" sizeInMB="8192" cleanOnRoleRecycle="false"/>

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.

Return to top