我在 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....");
测试结果可以引用下图。
关于c# - 无法在 Azure 应用服务上生成日志 NLog 内部日志记录文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51794042/