skip to Main Content

I know this might be a repeated question, but I am asking it again because I am not able to find any specific answer.

I am new to Azure functions. I have written an Azure functions in Java. I have a requirement to save the logs into files which will be Daily rolling log files (i.e. new log file should be created each day with the name %fileName%_ddmmyy)

When I use context.getLogger() , I am able to see the logs under Application Insights and Azure Monitor, but I cant find any option to save them into a log file. If I use Log4j, etc, I cannot see the logs under Application Insights and Azure Monitor.

I want to be able to see the logs under Application Insights and Azure Monitor as well as save them to log file which will rotate daily.

Is there any way using which I can achieve this scenario ? Any help would be appreciated.
PS : I need it in Java only. I am using java8.

2

Answers


  1. AFAIK, you can export manually everyday Logs like below using export option in Logs section of function app or application insights logs:

    enter image description here

    Alternatively, you can use diagnostic setting of function and send logs to your Storage Account or else to Log Analytic workspace. This is an example workaround:
    https://stackoverflow.com/a/73383532/17623802

    Login or Signup to reply.
  2. Go to Function App Resource -> Find Diagnostic settings under Monitoring
    Click on Add diagnostic setting
    Give a name of your Diagnostic setting name
    You can choose to export all logs and metrics or you can select from specific categories.
    and then select Archive to storage account
    Select the subscription and storage account
    DONE.

    For More info -> https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitor-log-analytics?tabs=csharp

    ALTERNATE
    If above doesn’t work then you can also create stream analytics jobs and dump the logs data in storage account.
    https://learn.microsoft.com/en-us/azure/stream-analytics/app-insights-export-stream-analytics

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search