Azure functions log to blobstorage

Viewed 203

I have an azure functions and iam using the logging function:

log.Info("log1").

I need to store the logs on blobstorage as txt file or similar. Is there a better integrated way to do it via rules on application insights?

1 Answers

As an Azure Function can have any number of bindings, you can utilize the blob output binding to upload log as a blob. Here's an example in .Net.

[FunctionName("MyFunction")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    [Blob("test", Connection = "ConnectionStringAppSetting")] BlobContainerClient output,
    ILogger log)
{
    string logContent = "C# HTTP trigger function processed a request.";
    log.LogInformation(logContent);

    await output.UploadBlobAsync("log", BinaryData.FromString(logContent));

    return new OkObjectResult("Function executed successfully");
}

Refer to this documentation for samples in all supported languages.

Related