【问题标题】:ASP.NET Core logging with NLog and MS SQLServer in Azure在 Azure 中使用 NLog 和 MS SQLServer 进行 ASP.NET Core 日志记录
【发布时间】:2017-08-25 20:21:27
【问题描述】:

我想在要部署到 Azure 的 ASP.NET Core 项目中实现 NLog。

我正在使用https://github.com/damienbod/AspNetCoreNlog中建议的代码

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

在 nlog.config 中:

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

在 Startup 类中:

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

【问题讨论】:

  • 我发现这个看起来可能就是你要找的东西damienbod.com/2016/08/17/…
  • 该页面也没有说明如何修改对“C:\git\...”的所有引用,以便它可以在 Azure 中工作。
  • 你可以在 azure 中写入文件吗?
  • 是的,在这里回答。 stackoverflow.com/questions/12964129/… 我想我可以使用 Server.MapPath 来更改 Startup 类。如何在配置文件中做到这一点?
  • 找到了答案。 intellitect.com/…

标签: asp.net-core azure-web-app-service nlog


【解决方案1】:

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 文件夹和内部日志文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多