Search code examples
asp.net-coreloggingazure-web-app-serviceazure-application-insightsilogger

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


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?


Solution

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

    To set up logging for Azure App Service:

    Other than Application Insights, you can use below approach:

    • Open your web app=> Go to Monitoring in the left pane=> App Service Logs:

    Windows:

    If your App Service is running on windows,

    • Enable Application Logging (File System) or Application Logging(Blob) and Save.
    • If you are enabling Application Logging (Blob), you have to select Storage account and container to write the logs.
    • Filesystem is for temporary purpose which helps in debugging and turns off in 12 hours. But the Blob can be used for long-term logging purpose.

    enter image description here

    Linux:

    If your App Service is running on windows, Enable Application Logging (File System):

    enter image description here

    You can check the real-time logs in LogStream:

    enter image description here

    References:

    Azure App Service Logging: How to Monitor Your Web Apps in Real-Time (microsoft.com)

    ASP.NET Core Blazor logging | Microsoft Learn