简体   繁体   English

我们可以将 azure 函数日志保存到文件中吗?

[英]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.

相关问题 我们可以在 azure 管道 yaml 文件中编写用户定义函数吗? - Can we write user define functions in azure pipeline yaml file? 我们可以在Azure OMS中获取自定义日志吗 - Can we fetch custom logs in Azure OMS 我们可以将挂载点保存在 azure 突触中吗 - Can we save the mount point in azure synapse 将文件保存到 Azure 函数中的临时位置 - save file to temporary location in Azure Functions 如何访问我的 Azure Functions 的日志? - How can I access my Azure Functions' logs? 我们可以在 Azure DevOps 中锁定文件吗? - Can we lock a file in Azure DevOps? 我们可以将azure函数用于传入的XML帖子吗 - Can we use azure functions for an incoming XML post 我们可以在没有管理员权限的情况下在 VSCode 中本地运行 azure 函数吗 - Can we run azure functions locally in VSCode without admin rights 我们可以使用本地 SQL Server 作为 AzureWebJobsStorage 运行容器化的 Azure Functions 吗? - Can we run containerized Azure Functions with local SQL Server as the AzureWebJobsStorage? 我们可以在私有云中使用 Azure PaaS 资源,例如 Azure 数据工厂或 Azure 功能吗? - Can we use Azure PaaS resources like Azure Data Factory or Azure Functions in a private cloud?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM