PowerShell is capable of streaming diagnostic log files. Learn how to download the logs using PowerShell or how to stream them through the Azure portal.
- [Instructor] Now that we've enabled our diagnostic logs for the app, let's go ahead and download those logs. I have already logged into PowerShell ISE, or the Integrated Scripting Environment, and I've done so as administrator. I've already set my subscription as well. One thing to note here is that when we download the logs they're going to download to your current directory. I do not want my logs downloading to my windows system 32 folder, therefore, I'm going to change my directory.
I'm simply going to change to my temp directory. Now I'm going to go ahead and save the website log files. To do so I'll use the commandlet save-AzureWebsiteLog and then I'll provide the name of the app. It doesn't take long. Now let's go ahead and take a look at our temp directory. And you'll see that we do now have a logs.zip file.
Keep in mind these will be downloaded as zip files. There may be times where you'd like to stream those logs real-time. We can also do that from PowerShell. We will use the command Get-AzureWebsiteLog, and provide the name with the parameter Tail. This will take a few moments.
What this does is connects to the web app and will begin streaming the information to our PowerShell window as events occur in the web app. Because we're not doing anything in the web app, there really won't be any detail here, but this shows you the command that you can use to do this within PowerShell. As you can see we do not have any traces in the last minute and this will just continue to cycle through this with the same error. For debugging purposes you'll want to add trace code into your app. I'm going to go ahead and stop this.
Next we're going to look at how we can stream this within the Azure portal as well. We are back in the web app. I'm going to scroll all the way down again to log stream. This will look very similar to what we just did using PowerShell. This will connect into our application logs. We also have the option to connect into our web server logs. Keep in mind in order for this to work you must have enabled the application logging for the file system and for the blob.
Again we have the same response as we had when we looked at this in PowerShell. I just wanted to show you the two options that you have for viewing your logs. We can also click into our web server logs. After a few moments we'll start to see some messages pop up in this window as well. There we go. And again because I have not set up any traces on these apps we don't have any information here.
One last thing before we leave here. You can also use the console to access your app via the portal. You'll find the console access under development tools. Again this is a nice to know. I'm not sure if you'll use it or not, but if you do need it it is there for your use. To recap, I showed you how to download your logs using PowerShell. Keep in mind that those logs will download as zip files into the current directory.
Therefore, if you do not want them saved to the directory you're working in, be sure to change that. I also showed you how you can stream your logs in PowerShell and then again in the portal. But streaming will only work once you've enabled application logging in the file system and blob within the diagnostic settings of your web app. And finally, we popped into the console access, which allows you to connect to your app via the console.
- Deploying Web Apps
- Creating App Service plans
- Deploying and moving apps
- Configuring app settings
- Managing Web Apps using PowerShell and CLI
- Configuring alerts
- Enabling diagnostic logs
- Retrieving and streaming logs
- Configuring Web Apps for scale and resilience