Exercise - Enable storage logging and view log data
In the Customer Portal scenario, you've decided you need more detailed information on the operations in progress rather than just the metrics that summarize performance. In this exercise, you'll enable logging for your storage account, rerun the sample application, and then download the log data that is generated.
Enable Storage Analytics logging
In the Azure portal, navigate to the storage account that you created in the previous exercise.
In the menu pane, under Monitoring (classic), select Diagnostic settings (classic).
Verify that Status is still set to On.
On the Blob properties tab, set Logging version to 2.0, select Read, Write, Delete, and Delete data. Set the retention period to seven days.
Switch to the Cloud Shell running PowerShell.
To verify that logging for blob storage has been enabled successfully, run the following command. Specify your storage account name, and account key where indicated.
$context = New-AzureStorageContext -StorageAccountName <your-storage-account-name> -StorageAccountKey <your-storage-account-key> Get-AzureStorageServiceLoggingProperty -Context $context -ServiceType Blob
The output should look like this.
Version LoggingOperations RetentionDays ------- ----------------- ------------- 2.0 All 7
Run the sample app
Move to the storageapps/StorageTest folder. This folder contains the code for the sample app that you ran in the previous exercise. The app simulates uploading and downloading files to and from blob storage.
Run the sample app as follows. Replace <your connection string> with the connection string for your storage account. Ensure that you surround your connection string with double-quotes.
dotnet run "<your connection string>" testcontainer
Download log data
On your desktop, return to Azure Storage Explorer.
Under Storage Accounts, under your storage account, expand Blob Containers, and you should see a container named $logs, with a folder named blob. If this container doesn't appear, wait for a few minutes while Storage Analytics processes the log data, and then select Refresh in the toolbar.
Select blob in the detail panel, and then navigate through the folder structure to the folder containing the latest set of log files. You should see a set of files similar to the files in the following example image.