Hi @amar, Unfortunately, no, there isn't a method for fetching the logs from a Windows app service. Logs for a Windows app service is written to the worker's filesystem and aren't accessible externally. However, for a workaround, you can stream the logs you're interested in to Log Analytics. You can use the Log Analytics API, see Overview - Azure Monitor | Microsoft Learn for more details, to pull that data through REST. Also have a look at Azure monitoring REST API walkthrough - Azure Monitor | Microsoft Learn for another way to pull Application Insight data through REST.
Is there any Microsoft Azure REST API for fetching the Windows App Service logs?
amar
0
Reputation points
I am trying to fetch all the logs of Azure App Service, for which I am using the below microsoft API:
As of now it's working fine for Linux App Service, but when I tried for Windows App Service it was not able to fetch the logs. Is there any other Microsoft API for fetching the logs for Windows App Service? Please help me with this issue.
FYI,
I have used the above API with my python code.
Thanks in advance.
import requests
import json
# Azure Monitor API endpoint for logs
monitor_logs_url = "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/containerlogs?api-version=2022-03-01"
# Your Azure AD authentication credentials (replace with actual values)
tenant_id = "your_tenant"
client_id = "your_id"
client_secret = "your_secret"
resource = "https://management.azure.com/"
# Get an access token using Azure AD authentication
token_endpoint = f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"
token_data = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"resource": resource,
}
token_r = requests.post(token_endpoint, data=token_data)
access_token = token_r.json()["access_token"]
# print(access_token)
# Make a POST request to fetch logs
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
query_body = {
"query": "",
"timespan": "PT12H" # Customize the timespan as needed
}
response = requests.post(monitor_logs_url, headers=headers, json=query_body)
# Handle the response (parse and process logs or metrics)
if response.status_code == 200:
logs_data = response.text
print("Logs data:", logs_data)
# Process logs_data (if needed)
else:
print(f"Failed to fetch logs. Status code: {response.status_code}")
print(f"Response content: {response.content}")
1 answer
Sort by: Most helpful
-
Ryan Hill 29,651 Reputation points Microsoft Employee
2024-01-12T04:32:37.4066667+00:00