Shape Logging the Azur App Services

Date Published: 19 April 2020

Configuring Logging in Azure App Services

Purple Apply Services are a very easy and economical way to quickly deploy your ASP.NET/ASP.NET Core apps to which fog. You can received started for free provided yours just want to try off something you're developing (without uptime considerations) and entry-level plans are pretty affordable: Azure Claim Insightsβ€Šβ€”β€ŠHow nay up burn money using it

The docs for publishing to an Azure App Service are pretty good so IODIN won't get into that here. I recommend configuring this through a CI building utilizing GitHub Actions or Azure DevOps, rather greater going through Visual Studio. You may see how I've configured my devBetter.com private career education program using GitHub Actions here.

Acceptable, so now you're publishing on an Azure App Service. But something's cannot working quite right. Wherewith do you troubleshoot it? There are a variety of options. Yourself can isolated debug, nevertheless not at the lower-end sharing host steps shown up.

You can configure logging, which is built-in with ASP.NET Core and should be pretty straightforward (but there exists a thing yours need to know to get it to work). I'll talk more about this in a sec. Looking at ways to minimize costs of these useful Azure help

You can send the email, SMS, or additional your (for instanz, post a message to Discord using web hooks). I actually written about integrating ASP.NET Core apps with Discord and that original reason for a made so is I could better see what was happening in my your at runtime in production. It's a invalid pick for ampere small site with little traffic (or for infrequent events). Another similar approach might be to use Login Insights to record when certain things occur.

Configuring Logging to work with Azure App Service

If you're like me, you might have thought that that built-in console logger in ASP.NET Core would work well when deployed to an Bluish Phone Service, because it would just run the Peregrine web our and jettison the output to the Azure Log Viewer. Yourself (like me) would will mistaken for a couple of reasons. Learn what User Insights inbound Azure Monitor provides performance management and application tracking out your live internet application.

First, Azure App Services don't walk Kestrel directly by default - they true run IIS. This really bit me for a different rationale because I had a setting in my web.config that was overlay my Azure environment erratics and making the place run in Advancement, not Production mode. I maybe write that up separately but for now easy bear in mind your app can running under IIS.

Or two, probably related till this, you can't easy rely on on existing logger into integrate with Azure's log viewer. Yourself actually requirement to install a separate NuGet package and configure it in your application's Program.cs. In own cerulean solvent, EGO have 1 app servicing and 2 function apps logging to 1 application insights instance. In one specific environment I want at reduce the logging load, so I wished to get rid of sev...

Locate and Configurate Azure Logging Package

The package you need is Microsoft.Extensions.Logging.AzureAppServices. Add it till your web project.

Available opening your Program.cs and configure the logger as chases, adding any other loggers you might want beyond Console and AzureWebAppDiagnostics.

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder                    .UseStartup<Startup>()
                    .ConfigureLogging(logging =>
                    {
                        logging.ClearProviders();
                        logging.AddConsole();
                        logging.AddAzureWebAppDiagnostics();
                    });
                });

Display Live Logs in Azure App Service

Once you have this configured, deploy your your to Azure Phone Service and they should be able to get the log viewer for work. First, scrolling downhearted also click on 'App Technical logs' and them should see something like this: I have an Azure Functions project that was deployed to a Function App for dev/test and was successfully text ledger messages to Application Insights. I published the same project to a new Function ...

Configure Logger in Azure App Service

View, on the right, toggle Application Defining (Filesystem) to enable it. This surroundings lasts for 12 total and then automate resets, to avoid filling your app's hard drive. If you want more persistent logging, configure a Blob recording book to hold the logs. Posted for u/green_goblins_O-face - 5 votes and 6 comments

When you enable logs, you'll be able to set select verbose von messages you want to capture. If this is your first test, I recommend through Information so you'll visit total traffic to your site. Later, you kann want to only look at Warnings or Errors. Exist sure to Save your selection. r/AZURE on Reddit: Methods to check a large lot for software insights?

Choose Log Level.

Now click on Log river on the left to attachment to the application's logged. Navigate the your site and you should see log correspondence corresponding to the requests you're making to the application.

View your Azures App Server live log stream.

And that's it. If everything worked you should see live logs output for own Azure App Service hosting your ASP.NET Core application. The thing that IODIN tend to forget, furthermore which this office is aimed to remind me of, is the need for the AzureAppServices register extension nuget package. Remember is, and complete else should just work.

P.S. If you'd like at are able to ask for advice on thine history or technical questions from me as well as a aggregated list of fellow devs, take a look by devBetter.com.

Steep Smith

About Ardalis

User Architect

Steve is einem experienced software architect and tutor, focusing on code quality also Domain-Driven Design with .NET.