gpt4 book ai didi

.net - Azure Service Fabric 使用 log4net 将日志记录到 AppInsights 中

转载 作者:行者123 更新时间:2023-12-02 06:21:00 25 4
gpt4 key购买 nike

我在 Azure 和“Service Fabric”中有一个名为“App Service”的网站,其中包含许多用于后台任务的服务。对于日志记录,我想使用 log4net 并分析 AppInsights。喜欢:

网站 --> log4net --> AppInsights 附加程序 --> AppInsights

Service Fabric --> log4net --> AppInsights 附加程序 --> AppInsights

问题是:实现所描述的日志记录流程的正确方法是什么,其想法是使用 log4net 进行日志记录并使用 AppInsights 进行分析。我可以区分 AppInsights 中的日志与网站和服务结构吗?

最佳答案

The question is: what is the correct way to implement described logging flow, the idea is to log with log4net and analyze with AppInsights.

根据我的理解,您可以按照以下步骤使用 log4net 记录应用程序洞察:

通过 log4Net 添加诊断日志:

logger.Info("Hello world!!!");

在这里,我创建了我的 asp.net MVC 应用程序,配置了应用程序洞察并安装了相关包,然后在 Global.asax.cs< 的 Application_Start 方法下添加了以下配置 文件如下:

log4net.Config.XmlConfigurator.Configure();

然后,我将我的 Web 应用程序部署到我的两个 Azure Web 应用程序,然后我可以按如下方式搜索日志:

enter image description here

And can I distinguish logs in AppInsights from website and service fabric.

您可以利用Analytics in Application Insights并编写查询以根据您的过滤器区分来自不同服务的日志,如下所示:

enter image description here

此外,我更愿意为我的每个 Azure Web 应用程序创建一个新的应用程序见解,因为每月有 1GB 免费空间,而且我可以轻松管理我的诊断日志记录。

关于.net - Azure Service Fabric 使用 log4net 将日志记录到 AppInsights 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44928369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com