How can I collect custom text logs from Linux App Service file system in Azure Monitor?

M. Vaihinger 45 Reputation points
2023-04-26T11:20:58.0066667+00:00

I'm trying to collect custom text logs in Azure Monitor from log files saved to the file system of a Linux App Service. But I am failing to do so. What's the best way to collect custom logs from Linux App Service? Note that I don't want to rely purely on AppServiceConsoleLogs, as I noticed that they are missing some of our logs. What I've tried so far:

  • Collect legacy custom text logs using Log Analytics agent: I tried to set the log collection up using the Legacy custom logs feature of Log Analytics workspace as described here: https://learn.microsoft.com/en-us/azure/azure-monitor/agents/data-sources-custom-logs. Our program continuously writes logs to text files in /wwwroot/<log_directory>/.log*. I configured this path as source for a custom log table in Log Analytics workspace. I see the custom table in Log Analytics workspace, but it is empty. Also, as of today, this feature is not available anymore in the portal, even though the docs state that it'll be available until end of 2024. Thanks in advance for your insights!
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,658 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,961 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,551 Reputation points Moderator
    2023-04-27T06:00:54.4833333+00:00

    @M. Vaihinger , Thank you for your question.

    I understand that you are trying to collect logs from your application to Log Analytics workspace. However, I was not sure of how you have deployed the app service. I am providing information on the 2 main ways through which the application can be hosted and related steps required to collect the custom logs.

    Hosted on Azure App Service - this is fully managed platform for hosting App. In this scenario you don't get access to the underlying VM and Azure maintains it for you. To collect custom logs from this type of app deployment, you can

    1. Enable Diagnostic settings for the App Service to forward custom logs to a Log Analytics workspace.
    2. Enable Application Insights and use ILogger based logging to send logs to AppInsights/LA worksapce directly (without enabling the diagnostic settings.)

    Note that, with this kind of hosting, the Log Analytics Agent Or Azure Monitor agent do not come in picture, as they are used for collecting information from Virtual machines (which is platform managed in this case).

    Hosted on VM - You can also host Application on Azure VM where you would have full control of VM. In this case you can use Azure Monitor agent (the legacy - Log Analytics Agent OR the new - Azure Monitor Agent). In this case also, you have the following options for collection of logs:

    1. Enable Application Insights and use ILogger based logging to send logs to AppInsights/LA worksapce directly - similar to app service monitoring. The same mechanism can also be used here where the AppInsights is enabled for the application hosted on VM and custom logs can be sent to AppInsights (which uses LA workspace for storing the logs)
    2. If there are logs which are in custom location (outside the framework based logging, for example text written to custom file path), you can use the Azure Monitor Agent to collect logs from such file. I would advise using the latest Azure Monitor Agent to collect logs from these files. For details, see Collect text logs with Azure Monitor Agent

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.


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.