How can I set up simple logging for an Azure App Service?

David Thielen 3,186 Reputation points
2023-07-10T21:44:22.49+00:00

Hi all;

There are a ton of resources to set up logging for an Azure app service, but all I have found are fairly complex setting up a ton of stuff. This is for a Blazor server (ASP.NET Core) app that uses ILogger for all logging.

What I want is the equivalent of there's a log file and I can search for two things:

  1. All errors logged
  2. Specific text in a log message

So I need the logs to be saved off somewhere where I can then view this. I know I can do it with Application Insights but that strikes me as overkill. I know writing to a file won't work because any given VM might be swapped out by Azure and then bye bye log file. Serilog, even more so than Application Insights, lot of work for this simple need.

So... is there a way to do this? Or should I use Application Insights for this?

thanks - dave

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,257 questions
{count} vote

Accepted answer
  1. VenkateshDodda-MSFT 23,781 Reputation points Microsoft Employee
    2023-07-12T04:53:32.2033333+00:00

    @David Thielen](/users/na/?userid=2e000d14-7fa3-4e41-9299-8306855b228f) Thanks for your response. Please find the below response for your follow questions.

    The 12 hours information related to storing the logs in file system is for temporary and debugging purpose only and for long retention you need to either use application insights or enabling diagnostic settings would be helpful. Even your webapp is scaled out to 4 or N (number of instances) application insights will be able to scale along with the App Service as it becomes part of Application and its setting.

    Questions related to Diagnostics settings:

    1.Anything I should add to my ILogger message format configuration to identify the server each log message came from?

    A: To distinguish/identify the source of logs, you can configure telemetry.Context.Cloud.RoleName and telemetry.Context.Cloud.RoleInstance in your application telemetry configuration as mentioned here.

    2.Messages from all servers will all go to the same blog - correct?

    A: Based on my tests, we have observed that an individual blob file will be generated for each instance.

    3.Any suggestions on how I should configure the disgnostic settings to save everything to the blob.

    A: While enabling the diagnostic settings select the destination as Storage account to send webapp logs as shown below.

    User's image

    4.Any suggestions on what tool(s) I should use to review the blob?

    A: If you store logs in storage account you manually need to review it and if you store the logs in application insights you can query them using some KQL queries.

    Feel free to reach back to me if you have any further questions on this.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.