ASP.NET 在 Azure 中使用 NLog 和 MS SQLServer 进行核心日志记录

ASP.NET Core logging with NLog and MS SQLServer in Azure

我想在我要部署到 Azure 的 ASP.NET 核心项目中实施 NLog。

我正在使用 https://github.com/damienbod/AspNetCoreNlog

中建议的代码

如何修改以下行以允许它在 Azure 中使用?

在nlog.config中:

internalLogFile="C:\git\damienbod\AspNetCoreNlog\Logs\internal-nlog.txt"

在启动中class:

LogManager.Configuration.Variables["configDir"] = "C:\git\damienbod\AspNetCoreNlog\Logs";

this article中:还定义了一个内部日志文件,这样如果日志配置有问题,你可以找出原因。我们可以知道内部日志文件通过配置internalLogFile="C:\git\damienbod\AspNetCoreNlog\Logs\internal-nlog.txt保存在磁盘上,根据我的测试,我们可以修改它以将内部日志文件保存在Azure Web应用服务器上。

我将其配置为:

internalLogFile="D:\home\site\AspNetCoreNlog\Logs\internal-nlog.txt"

LogManager.Configuration.Variables["configDir"] = "D:\home\site\AspNetCoreNlog\Logs";

该应用程序在 Azure Web 应用程序服务上运行良好,我可以通过 Kudu console.

访问 AspNetCoreNlog 文件夹和内部日志文件