【问题标题】:Unable to generate log NLog internal logging file on Azure App Service无法在 Azure 应用服务上生成日志 NLog 内部日志记录文件
【发布时间】:2019-01-18 12:20:22
【问题描述】:

我在 Azure 应用服务上运行网站和 Web 作业,我想启用 NLog 内部调试来解决一些日志记录问题。在我的 NLog 配置代码中,我这样做:

InternalLogger.LogLevel = LogLevel.Trace;
InternalLogger.LogFile = "nlog.txt";

在开发过程中本地运行时,nlog.txt 会显示在应用程序二进制目录 (bin) 中。在 Azure 上它不显示。假设可能是文件系统权限问题,我将代码更改为:

InternalLogger.LogLevel = LogLevel.Trace;
InternalLogger.LogFile = @"d:\logfiles\nlog.txt";

Azure 应用服务保证d:\logfiles\ 目录是可写的。但是仍然没有nlog.txt 文件。

想法?

【问题讨论】:

  • 您是否尝试从您的应用程序写入目录d:\logfiles\test.txt。只是为了看看你的应用程序是否有适当的权限?
  • @Rolf 是的 - 我把所有的日志文件都写在那里。
  • 确保在创建任何 Logger 对象之前配置 InternalLogger,即使是 Program.cs 类中可能存在的静态对象。
  • 更正 - 我的意思是 `d:\home\logfiles`。我的代码是正确的,但我在这里写错了。

标签: c# azure logging nlog azure-app-service-envrmnt


【解决方案1】:

其实LogFiles文件夹在Azure中D:\home下(你提到文件路径是d:\logfiles\,所以我也尝试直接在D:驱动下创建LogFiles文件夹,但是500内部服务器发生错误)。

请尝试将 InternalLogger.LogFile 的值更改为 d:\home\LogFiles\nlog.txt,例如 InternalLogger.LogFile= @"d:\home\LogFiles\nlog.txt"

我可以通过使用以下代码在 azure 中看到生成的 nlog.txt:

 InternalLogger.LogLevel = LogLevel.Trace;
 InternalLogger.LogFile = @"d:\home\LogFiles\nlog.txt";
 InternalLogger.Log(LogLevel.Trace, "a text message from here....");

测试结果可以参考下图。

【讨论】:

  • 我的代码是正确的 d:\home\logfiles`; I just wrote it incorrectly here. Oddly, I changed the path to d:\local\temp` 是可写空间(但不推荐,因为操作系统可以随时擦除它)并且我成功编写了 nlog 内部记录器文件。这很奇怪,因为 d:\home\logfiles\ 正是 nlog 写入正常日志文件的位置!
  • 我的立场是正确的 - 我的代码确实是错误的 - 我指向了不正确的(只读)位置。哎……
猜你喜欢
  • 1970-01-01
  • 2021-04-23
  • 1970-01-01
  • 2016-01-13
  • 1970-01-01
  • 1970-01-01
  • 2012-03-28
  • 2014-06-16
  • 1970-01-01
相关资源
最近更新 更多