DirectoryConfiguration.Path Property
Assembly: Microsoft.WindowsAzure.Diagnostics (in Microsoft.WindowsAzure.Diagnostics.dll)
/** @property */ /** @attribute CompilerGeneratedAttribute() */ public String get_Path () /** @property */ /** @attribute CompilerGeneratedAttribute() */ public void set_Path (String value)
CompilerGeneratedAttribute public function get Path () : String CompilerGeneratedAttribute public function set Path (value : String)
Property Value
Type: System.StringReturns 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.
Warning |
|---|
| If your role instance or VM fails, any local logging data may be deleted. To prevent data loss, transfer data from local storage to persistent storage on a frequent interval. |
Examples
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 = RoleEnvironment.GetLocalResource("MyCustomLogs").RootPath;
The following code snippet shows the property in the context of a role’s OnStart() method. This method creates a new DirectoryConfiguration object, specifies the directory path for our custom logs, adds the configuration to our DiagnosticMonitorConfiguration object, and starts the DiagnosticMonitor with the new configuration.
public override bool OnStart()
{
// Get the default initial configuration for DiagnosticMonitor.
DiagnosticMonitorConfiguration diagnosticConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();
// Create a new DirectoryConfiguration object.
DirectoryConfiguration directoryConfiguration = new DirectoryConfiguration();
// Add the name for the blob container in Windows Azure storage.
directoryConfiguration.Container = "wad-custom-logs";
// Add the directory size quota.
directoryConfiguration.DirectoryQuotaInMB = 2048;
// Add the log path for the role using RoleEnvironment.GetLocalResource().
directoryConfiguration.Path = RoleEnvironment.GetLocalResource("MyCustomLogs").RootPath;
// Add the directoryConfiguration to the Directories collection.
diagnosticConfiguration.Directories.DataSources.Add(directoryConfiguration);
// Schedule a transfer period of 30 minutes.
diagnosticConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(30.0);
// Start the DiagnosticMonitor using the diagnosticConfig and our connection string.
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagnosticConfiguration);
return base.OnStart();
}
The following snippet from a ServiceDefinition.csdef file defines the MyCustomLogs directory.
<LocalResources>
<LocalStorage name="MyCustomLogs" sizeInMB="8192" cleanOnRoleRecycle="false"/>
</LocalResources>
Development Platforms
Windows Vista, Windows 7 and Windows Server 2008Target Platforms
Warning