Unable to generate log NLog internal logging file on Azure App Service
Asked Answered
S

1

5

I run websites and webjobs on Azure App Service and I want to enable NLog internal debugging to troubleshoot some logging problems. In my NLog configuration code I do:

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

When run locally during development, nlog.txt shows up in the application binary directory (bin). On Azure it does not show up. Assuming perhaps a file system permissions issue I changed the code to:

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

Azure App Service guarantees that the d:\logfiles\ directory is writable. Yet still no nlog.txt file.

Ideas?

Sevilla answered 10/8, 2018 at 21:6 Comment(4)
Have you tried to write to the directory d:\logfiles\test.txt from your application. Just to see if you application has proper permissions?Flounder
@Rolf Yes - I write all my log files there.Sevilla
Make sure to configure the InternalLogger before creating any Logger-objects even the static ones that might exist in the Program.cs class.Flounder
Correction - I meant `d:\home\logfiles`. My code was correct but I wrote it incorrectly here.Sevilla
B
7

Actually the LogFiles folder is under D:\home in Azure (you mentioned the file path is d:\logfiles\, so I also tried to create a LogFiles folder under D: drive directly, but an 500 internal server error occurs).

Please try to change the value to d:\home\LogFiles\nlog.txt for InternalLogger.LogFile, like InternalLogger.LogFile= @"d:\home\LogFiles\nlog.txt" .

I can see the nlog.txt generated in azure by using the following code:

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

You can refer to the pic below for test result.

enter image description here

Burdette answered 13/8, 2018 at 3:27 Comment(2)
My code was correct with d:\home\logfiles`; I just wrote it incorrectly here. Oddly, I changed the path to d:\local\temp` which is writable space (but not recommended because the OS can wipe it at any time) and I was successful in writing the nlog internal logger file. Which is seriously odd because d:\home\logfiles\ is exactly where nlog is writing the normal log files!Sevilla
I stand corrected - my code was indeed wrong - I was pointing to the incorrect (read-only) location. Oy...Sevilla

© 2022 - 2024 — McMap. All rights reserved.