DirectoryConfiguration 類別
組件: Microsoft.WindowsAzure.Diagnostics (在 microsoft.windowsazure.diagnostics.dll 中)
The DirectoryConfiguration class provides properties to configure a directory for storing logs and diagnostic data. By default, directories for IIS logs (for web roles only), failed request logs, and crash dumps are automatically configured. You can also configure additional custom logs.
The DirectoryConfiguration object is used by your role instance’s DiagnosticMonitorConfiguration. Specifically, you add the DirectoryConfiguration to the DataSources collection of a DiagnosticMonitorConfiguration class.
Example
The following code snippet demonstrates how to use DirectoryConfiguration in the context of a role’s OnStart() method. This method creates a new DirectoryConfiguration object, specifies the container name for our custom log directory, 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 ServiceConfiguration.cscfg file defines the MyCustomLogs directory.
<LocalResources>
<LocalStorage name="MyCustomLogs" sizeInMB="8192" cleanOnRoleRecycle="false"/>
</LocalResources>