如何为Azure应用服务设置简单的日志记录?

huangapple go评论70阅读模式
英文:

How can I set up simple logging for an Azure App Service?

问题

有很多资源可以为Azure应用服务设置日志记录,但我找到的都相当复杂,需要设置大量的内容。这是用于Blazor服务器(ASP.NET Core)应用程序,它使用ILogger进行所有日志记录。

我想要的是相当于有一个日志文件,我可以在其中搜索两件事情:

  1. 记录的所有错误
  2. 日志消息中的特定文本

因此,我需要将日志保存在某个地方,然后我可以查看它。我知道可以使用Application Insights来实现这一点,但这似乎有些过度。我知道写入文件不行,因为Azure可能会将任何给定的虚拟机替换掉,然后日志文件就没了。Serilog,甚至比Application Insights更复杂,对于这个简单的需求来说有点繁琐。

所以...有没有办法做到这一点?还是我应该使用Application Insights?

英文:

There are a ton of resources to set up logging for an Azure app service, but all I have found are fairly complex setting up a ton of stuff. This is for a Blazor server (ASP.NET Core) app that uses ILogger for all logging.

What I want is the equivalent of there's a log file and I can search for two things:

  1. All errors logged
  2. Specific text in a log message

So I need the logs to be saved off somewhere where I can then view this. I know I can do it with Application Insights but that strikes me as overkill. I know writing to a file won't work because any given VM might be swapped out by Azure and then bye bye log file. Serilog, even more so than Application Insights, lot of work for this simple need.

So... is there a way to do this? Or should I use Application Insights for this?

答案1

得分: 0

如何为Azure App Service设置简单的日志记录?

为Azure App Service设置日志记录:

除了使用Application Insights之外,您还可以使用以下方法:

  • 打开您的Web应用程序=>在左侧窗格中转到监视=>App Service日志:

Windows:

如果您的App Service正在运行Windows操作系统,

  • 启用应用程序日志记录(文件系统)或应用程序日志记录(Blob)并保存。
  • 如果您启用了应用程序日志记录(Blob),您必须选择存储帐户和容器以写入日志。
  • 文件系统用于临时目的,有助于调试,并在12小时后关闭。但Blob可用于长期记录目的。

如何为Azure应用服务设置简单的日志记录?

Linux:

如果您的App Service正在运行Windows操作系统,请启用应用程序日志记录(文件系统):

如何为Azure应用服务设置简单的日志记录?

您可以在LogStream中查看实时日志:

如何为Azure应用服务设置简单的日志记录?

参考资料:

Azure App Service日志记录: 如何实时监视您的Web应用程序 (microsoft.com)

ASP.NET Core Blazor日志记录 | Microsoft Learn

英文:

>How can I set up simple logging for an Azure App Service?

To set up logging for Azure App Service:

Other than Application Insights, you can use below approach:

  • Open your web app=> Go to Monitoring in the left pane=> App Service Logs:

Windows:

If your App Service is running on windows,

  • Enable Application Logging (File System) or Application Logging(Blob) and Save.
  • If you are enabling Application Logging (Blob), you have to select Storage account and container to write the logs.
  • Filesystem is for temporary purpose which helps in debugging and turns off in 12 hours. But the Blob can be used for long-term logging purpose.

如何为Azure应用服务设置简单的日志记录?

Linux:

If your App Service is running on windows, Enable Application Logging (File System):

如何为Azure应用服务设置简单的日志记录?

You can check the real-time logs in LogStream:

如何为Azure应用服务设置简单的日志记录?

References:

Azure App Service Logging: How to Monitor Your Web Apps in Real-Time (microsoft.com)

ASP.NET Core Blazor logging | Microsoft Learn

huangapple
  • 本文由 发表于 2023年7月11日 03:29:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定