[英]Can we save azure functions logs to a file?
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.我是 Azure 功能的新手。 I have written an Azure functions in Java.
我在 Java 中写了一个 Azure 函数。 I have a requirement to save the logs into files which will be Daily rolling log files (ie new log file should be created each day with the name %fileName%_ddmmyy)
我需要将日志保存到将成为每日滚动日志文件的文件中(即每天应创建名为 %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.当我使用 context.getLogger() 时,我可以在 Application Insights 和 Azure Monitor 下看到日志,但我找不到将它们保存到日志文件中的任何选项。 If I use Log4j, etc, I cannot see the logs under Application Insights and Azure Monitor.
如果我使用 Log4j 等,我在 Application Insights 和 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.我希望能够在 Application Insights 和 Azure Monitor 下查看日志,并将它们保存到每天轮换的日志文件中。
Is there any way using which I can achieve this scenario?有什么方法可以实现这种情况吗? Any help would be appreciated.
任何帮助,将不胜感激。 PS: I need it in Java only.
PS:我只在 Java 中需要它。 I am using java8.
我正在使用java8。
AFAIK, you can export manually everyday Logs like below using export option in Logs section of function app or application insights logs: AFAIK,您可以使用 function 应用程序或应用程序洞察日志的日志部分中的导出选项手动导出日常日志,如下所示:
Alternatively, you can use diagnostic setting of function and send logs to your Storage Account or else to Log Analytic workspace.或者,您可以使用 function 的诊断设置并将日志发送到您的存储帐户或日志分析工作区。 This is an example workaround: https://stackoverflow.com/a/73383532/17623802
这是一个示例解决方法: https://stackoverflow.com/a/73383532/17623802
Go to Function App Resource -> Find Diagnostic settings
under Monitoring
Go 到 Function 应用程序资源 -> 在
Monitoring
下找到Diagnostic settings
Click on Add diagnostic setting
单击
Add diagnostic setting
Give a name of your Diagnostic setting name
命名您的
Diagnostic setting name
You can choose to export all logs and metrics or you can select from specific categories.您可以选择导出所有日志和指标,也可以从特定类别中选择 select。
and then select Archive to storage account然后 select 存档到存储帐户
Select the subscription and storage account Select 订阅和存储帐户
DONE.完毕。
For More info -> https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitor-log-analytics?tabs=csharp更多信息-> https://docs.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.如果上述方法不起作用,您还可以创建 stream 分析作业并将日志数据转储到存储帐户中。 https://docs.microsoft.com/en-us/azure/stream-analytics/app-insights-export-stream-analytics
https://docs.microsoft.com/en-us/azure/stream-analytics/app-insights-export-stream-analytics
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.