{"id":11495,"date":"2018-02-07T08:00:26","date_gmt":"2018-02-07T16:00:26","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=11495"},"modified":"2018-02-07T08:00:26","modified_gmt":"2018-02-07T16:00:26","slug":"diagnosing-errors-on-your-cloud-apps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/diagnosing-errors-on-your-cloud-apps\/","title":{"rendered":"Diagnosing Errors on your Cloud Apps"},"content":{"rendered":"<p>One of the most frustrating experiences is when you have your app working on your local machine, but when you publish it it\u2019s inexplicably failing. Fortunately, Visual Studio provides handy features for working with apps running in Azure. In this blog I\u2019ll show you how to leverage the capabilities of Cloud Explorer to diagnose issues in Azure. If you\u2019re interested in developing apps in the cloud, we\u2019d love to hear from you. Please take a minute to complete our <a href=\"https:\/\/microsoft.qualtrics.com\/jfe\/form\/SV_9ufJLvsguqlwBTL\" rel=\"noopener\" target=\"_blank\">one question survey<\/a>.<\/p>\n<h3>Prerequisites &#8211; If you want to follow along, you\u2019ll need<\/h3>\n<p><a href=\"https:\/\/www.visualstudio.com\/downloads\/\" rel=\"noopener\" target=\"_blank\">Visual Studio 2017<\/a> with <a href=\"https:\/\/www.visualstudio.com\/vs\/support\/selecting-workloads-visual-studio-2017\/\" rel=\"noopener\" target=\"_blank\">Azure development workload<\/a> installed. &#8211; This blog assumes you have an Azure subscription and have an App running in Azure App Services. If you don\u2019t have an Azure subscription, click <a href=\"https:\/\/azure.microsoft.com\/en-us\/free\/\" rel=\"noopener\" target=\"_blank\">here<\/a> to sign up for free credits. &#8211; For the purposes of this blog, we&#8217;ve developed a simple one-page web app. The source is available <a href=\"https:\/\/github.com\/justcla\/ListBlobFiles\">here<\/a>.<\/p>\n<h4>Open the solution If you have your app running on Azure, open the solution in Visual Studio. Alternatively,<\/h4>\n<p><a href=\"https:\/\/github.com\/justcla\/ListBlobFiles\">clone the source<\/a> for the sample app and open it in Visual Studio. Publish the app to Microsoft Azure App Services.<\/p>\n<h4>Connect to your Azure subscription with Cloud Explorer Cloud Explorer is a powerful tool that ships with the Azure development workload in Visual Studio 2017. We can use Cloud Explorer to view and interact with the resources in our Azure subscription. To view your Azure resources in Cloud Explorer, enable the subscription in the Account Manager tab. &#8211; Open<\/h4>\n<p><strong>Cloud Explorer<\/strong> (View -&gt; Cloud Explorer) &#8211; Press the <strong>Account Management<\/strong> button in the Cloud Explorer toolbar. &#8211; Choose the Azure subscription that you are working with, then press <strong>Apply<\/strong>. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerAccountManager-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerAccountManager-1-1.png\" alt=\"Cloud Explorer - Account Manager\" width=\"350\" class=\"alignnone size-full wp-image-11545\" \/><\/a> Your Azure subscription now appears in the Cloud Explorer. You can toggle the grouping of elements by <strong>Resource Groups<\/strong> or <strong>Resource Types<\/strong> using the drop-down selector at the top of the window.<\/p>\n<h3>View Streaming Logs When I ran my app after publishing, there was an error. The error message shown on the web page was not very descriptive. So what can I do? How can I get more information about what&#8217;s going wrong? One easy way to diagnose issues on the server is to inspect the application logs. Using Cloud Explorer, you can access the streaming logs of any App Service in your subscription. The streaming logs output a concatenation of all the application logs saved on the App Service. The default log level is \u201cError\u201d. To<\/h3>\n<p><strong>view streaming logs<\/strong> for your application running on Azure App Services: &#8211; Expand the subscription node and select your App Service. &#8211; Click <strong>View Streaming Logs<\/strong> in the Actions panel. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerActions3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/CloudExplorerActions3-2.png\" alt=\"Cloud Explorer - View Streaming Logs\" width=\"350\" class=\"alignnone size-full wp-image-11575\" \/><\/a> The Output window opens with a new log stream from the App Service running on the cloud. &#8211; If you\u2019re using the sample app, refresh the page in the web browser and wait for the page to complete rendering. This might take ten seconds or more, as the server waits for the fetch operation to time out before returning the result. You can read the log messages to see what&#8217;s happening on the server. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StreamingLogsErrors.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StreamingLogsErrors-2.png\" alt=\"Streaming Logs - Showing Errors\" width=\"1968\" height=\"303\" class=\"alignnone size-full wp-image-11525\" \/><\/a> If you switch to Verbose output logging, you see a lot more. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StreamingLogsVerbose.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/StreamingLogsVerbose-2.png\" alt=\"Streaming Logs - Verbose view\" width=\"1972\" height=\"537\" class=\"alignnone size-full wp-image-11535\" \/><\/a> Notice the [Error] that appears in the streaming logs: \u201cException occurred while attempting to list files on server.\u201d It doesn\u2019t tell us much, but at least now we can start looking in the ListBlobFiles.StorageHelper for clues. We know it works locally, so we&#8217;ll need to debug the version running on the cloud to see why it&#8217;s failing. For that, we need remote debugging. Once again, Cloud Explorer to the rescue!<\/p>\n<h3>Remote Debugging App Service running on Azure Using Cloud Explorer, you can attach a remote debugger to applications running on Azure. This lets you control the flow of execution by breaking and stepping through the code. It also provides an opportunity to view the value of variables and method returns by utilizing Visual Studio\u2019s debugger tooltips, autos, watches, call stack and other diagnostic tools.<\/h3>\n<h4>Publish a Debug version of the Web App Before you can attach a debugger to an application on Azure, there must be a debug version of the code running on the App Service. So, we&#8217;ll re-publish the app with Debug release configuration. Then we&#8217;ll attach a remote debugger to the app running in the cloud, set breakpoints and step through the code. \u2022 Open the publish summary page (Right-click project, choose &#8220;Publish\u2026&#8221;) \u2022 Select (or create) the publish profile for your web app \u2022 Click<\/h4>\n<p><strong>Settings<\/strong> \u2022 When the settings dialog opens, go to the <strong>Settings<\/strong> tab. \u2022 In the <strong>Configurations<\/strong> drop-down, select &#8220;Debug&#8221;. \u2022 Save the publish profile settings. \u2022 Press **Publish **to republish the web app <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/PublishDebugConfiguration.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/PublishDebugConfiguration-2.png\" alt=\"Publish Debug Configuration\" width=\"650\" class=\"alignnone size-full wp-image-11505\" \/><\/a><\/p>\n<h4>Attach Remote Debugger You can attach a remote debugger to allow you to step through the code that\u2019s running on your Azure App Service. This lets you see the values of variables and watch the flow of control in your app. To<\/h4>\n<p><strong>attach a remote debugger<\/strong>: \u2022 In the Cloud Explorer, select the web app. \u2022 Click <strong>Attach Debugger<\/strong> in the Actions panel. Visual Studio will switch over to Debug mode. Now you can set breakpoints in the code and watch the execution as the program runs.<\/p>\n<h4>Set breakpoint and execute the code If you\u2019re following along from the sample, try this: \u2022 Set breakpoints in the<\/h4>\n<p><strong>GetBlobFileListAsync()<\/strong> method of the StorageHelper.cs \u2022 Refresh the page in the web browser \u2022 Execution will stop at your first breakpoint. \u2022 Hover your mouse cursor over the <strong>_storageConnectionString<\/strong> variable and inspect its value. \u2022 Notice that the connection string is &#8220;UseDevelopmentStorage=true&#8221;. <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/RemoteDebugging2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/RemoteDebugging2-2.png\" alt=\"Remote Debugging in Visual Studio\" width=\"1507\" height=\"1177\" class=\"alignnone size-full wp-image-11585\" \/><\/a> Problem found! We&#8217;re referencing our local Storage (\u201cUseDevelopmentStorge=true\u201d), which won&#8217;t work in the cloud. To fix it, we\u2019ll need to provide a connection string to the app running in the cloud that points to our Blob storage container. Complete the debugging session. &#8211; Press F5 to allow the request to complete. &#8211; Then press Shift+F5 to stop the remote debugging session.<\/p>\n<h3>Next steps<\/h3>\n<p><strong>Re-publish with Release configuration<\/strong> Once you\u2019ve finished debugging and your app is working as expected, you can republish a Release version of the app for better performance. Go to the Publish page, find the Publish Profile, select &#8220;Settings\u2026&#8221; and change the configuration to &#8220;Release&#8221;.<\/p>\n<h3>Related Links Get started with Azure Blob storage using .NET<\/h3>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-dotnet-how-to-use-blobs\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-dotnet-how-to-use-blobs<\/a> Use the Azure Storage Emulator for development and testing <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/common\/storage-use-emulator\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/common\/storage-use-emulator<\/a> Introduction to Razor Pages in ASP.NET Core <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/razor-pages\/?tabs=visual-studio\">https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/razor-pages\/?tabs=visual-studio<\/a> ASP.NET Core &#8211; Simpler ASP.NET MVC Apps with Razor Pages MSDN Magazine article by Steve Smith <a href=\"https:\/\/msdn.microsoft.com\/en-us\/magazine\/mt842512.aspx\">https:\/\/msdn.microsoft.com\/en-us\/magazine\/mt842512.aspx<\/a> Upload image data in the cloud with Azure Storage <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-upload-process-images\">https:\/\/docs.microsoft.com\/en-us\/azure\/storage\/blobs\/storage-upload-process-images<\/a> Azure Blob Storage Samples for .NET <a href=\"https:\/\/github.com\/Azure-Samples\/storage-blob-dotnet-getting-started\">https:\/\/github.com\/Azure-Samples\/storage-blob-dotnet-getting-started<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most frustrating experiences is when you have your app working on your local machine, but when you publish it it\u2019s inexplicably failing. Fortunately, Visual Studio provides handy features for working with apps running in Azure. In this blog I\u2019ll show you how to leverage the capabilities of Cloud Explorer to diagnose issues [&hellip;]<\/p>\n","protected":false},"author":467,"featured_media":21399,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,327,7252],"tags":[7538,7539,7540],"class_list":["post-11495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-azure","category-cloud","tag-apps","tag-cloud","tag-diagnosing"],"acf":[],"blog_post_summary":"<p>One of the most frustrating experiences is when you have your app working on your local machine, but when you publish it it\u2019s inexplicably failing. Fortunately, Visual Studio provides handy features for working with apps running in Azure. In this blog I\u2019ll show you how to leverage the capabilities of Cloud Explorer to diagnose issues [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/11495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/467"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=11495"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/11495\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/21399"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=11495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=11495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=11495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}