Where is the log file created when debugging Azure Function in Visual Studio
Asked Answered
E

1

6

I have a Timer Azure Function which I execute in VS. Right click on the Azure Function project and Debug. The function has an ILogger log.

Inspecting the log object I can see that is has two loggers

  • Azure.Functions.Cli.Diagnostics.ColoredConsoleLogger
  • Microsoft.Azure.WebJobs.Script.Diagnostics.FileLogger

I also can see that the RootLogPath is %temp%\LogFiles\Application\Functions.

However at that location there is only a "Host" folder. I expected to find a "Function" folder as well with the log file.

Do I need to enable somehow the File Logger? Do I miss anything?

Escuage answered 14/2, 2019 at 21:24 Comment(0)
P
9

To get file logs in local dev, we do have to modify the fileLoggingMode to always in host.json. The default debugOnly setting doesn't make function write file logs locally.

For v2 Functions

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always"
  }
}

For v1 Functions

{
    "tracing": {
      "fileLoggingMode": "always"
    }
}
Prevaricate answered 15/2, 2019 at 2:34 Comment(2)
Work also for me thank you! (voted). However, a bit concerned with the name "debugOnly" they chose. Maybe "azureOnly" or "productionOnly" would make more sense. When I am testing locally I am actually in "Debug" mode and the logger doesn't persist. It's misleading in my opinion, unless I missed something (very new to this topic)Synchroscope
Does "fileLoggingMode": "always" write logs to a file when debugging locally in VS, but it won't write to a file when published to Azure?Pahari

© 2022 - 2024 — McMap. All rights reserved.