I have a Azure function with HTTP trigger. For every HTTP request I need to save the logs of details the of post request to ADLS like time of trigger and request params.
Can anyone help me how can i do this?
Here is the Workaround I did to store the Azure Function Logs in ADLS Gen 2 where the logs contains the Function Execution Time, Started Time, Execution Result, etc.
To Create the Function App in ADLS Gen 2, First, you need to create the Storage Account of type ADLS Gen 2.
When you're creating the Storage Account, Check the box of Enable hierarchical namespace
to create an ADLS Gen 2 Account.
After Creating an ADLS Storage account, create a function app in that storage account using PowerShell Command: (For example DotNet
Stack)
New-AzFunctionApp -Name <APP_NAME> -ResourceGroupName AzureFunctionsQuickstart-rg -StorageAccount <STORAGE_NAME> -Runtime dotnet -FunctionsVersion 3 -Location '<REGION>'
ADLS Storage Account > File Shares > Your Function App > LogFiles > Application > Functions > Function > Your Function Name > here you can see the logs.
Suppose, Function Key is also a one of the parameter in Azure Function URL.
By default, this info will not be logged but we can customize the code to log this parameter and in the Traces table of Application insights, this information can be available.
const string key_Claim = "http://schemas.microsoft.com/2017/07/functions/claims/keyid";
var claim = req.HttpContext.User.Claims.FirstOrDefault(c => c.Type == key_Claim);
if(claim != null)
{
log.LogInformation( "The call was made using {0} named key", claim.Value);
}
In Application Insights [Logs]
The above Workaround I did in .Net Stack and here is an example code related to read parameters of Azure Function and store it in a blob files using NodeJS.