c# - 无法在 Azure 应用服务上生成日志 NLog 内部日志记录文件

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

我在 Azure 应用服务上运行网站和 webjob,我想启用 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 文件。

想法?

最佳答案

实际上,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....");

测试结果可以引用下图。

enter image description here

关于c# - 无法在 Azure 应用服务上生成日志 NLog 内部日志记录文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51794042/

相关文章:

javascript - 基于 Asp.net 中单选按钮列表的 Jquery 显示/隐藏

c# - 解决 C# 和 C++/CLI 项目之间的循环项目依赖性?

azure - 使用 PowerShell 和现有 VNET 创建 Azure VM

Azure WebApp 不将应用程序日志发送到 Blob 存储

java - 禁用 HttpClient 日志记录

c# - .RemoveRange 在 Entity Framework 中不首先获取数据库记录

c# - 在 List<int> 中查找(并替换)相邻的相等/相似元素

java.lang.RuntimeException : javax.net.ssl.SSLHandshakeException 异常

c# - 仅当 Blob 存在时才获取 Azure Blob 元数据

c# - 如何获取最后插入的记录