47

I'm relatively new to Azure and I just went through the tutorial on how to create a new Azure function, which is triggered when a new blob is created, and had this as the default code in it.

public static void Run(Stream myBlob, string name, TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}

From what I can see on the tutorial, I should be able to see some information in the "logs" area below the code, but nothing shows up, I've been checking for a solution for a while now but can't seem to find anything useful.

Any help would be greatly appreciated.

Kikanye
  • 1,198
  • 1
  • 14
  • 33

9 Answers9

63

The log window is a bit fragile and doesn't always show the logs. However, logs are also written to the log files.

You can access these logs from the Kudu console: https://[your-function-app].scm.azurewebsites.net/

From the menu, select Debug console > CMD

On the list of files, go into LogFiles > Application > Functions > Function > [Name of your function]

There you will see a list of log files.

Andy T
  • 10,223
  • 5
  • 53
  • 95
  • 2
    I have tons of logs that are missing. It doesn't seem to write them to file storage within a reasonable time frame and every log file past yesterday is missing. Do I have a botched setting somewhere? – th3morg May 15 '18 at 16:23
  • 1
    Closing completely browser tab and reopening it helped me out. Maybe some issues with SignalR posting to the browser? – Mariusz Dec 18 '18 at 15:19
  • This way works...sometimes. But not always. Checking log files in the folder directly is reilable. – boj Dec 13 '20 at 19:28
  • There is only current day log file in this directory. Any idea where previous logs were moved (different directory)? – Krishna Santosh Nidri Dec 13 '21 at 18:50
  • For my .NET 6 function (runtime v4 dotnet-isolated) I cannot access any logs via Kudu. There is no debug console :/ – Heinrich Ulbricht Jan 18 '22 at 15:07
  • 1
    Ok I was using a shared app service plan and Kudu (log) file access is not supported there. Using a dedicated one lets me access the files. – Heinrich Ulbricht Jan 18 '22 at 21:00
  • 1
    They don't always show here either – Christine May 31 '23 at 20:10
11

Following the advice here worked for me. Configuring Log Level for Azure Functions

If you want to see your logs show up immediately in the Portal console after you press "Run", then go to your "Function app settings" and add the following to your host.json file:

"logging": {
    "fileLoggingMode": "always",
    "logLevel": {
        "default": "Information",
        "Host.Results": "Error",
        "Function": "Trace",
        "Host.Aggregator": "Trace"
    }
}

Note that this only worked for Javascript functions. For locally developed functions in other languages, the console can be a bit skittish.

James Shapiro
  • 4,805
  • 3
  • 31
  • 46
  • This does not apply anymore. Also if you are running from a ziip file, you cannot edit hosts.json – DerpDerp May 05 '21 at 06:55
  • I set all the darn properties[0] to `Trace`, nothing below "Information" is ever visible in the streaming logs. At least for my .NET 6 isolated function app. [0]: https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2#configure-categories – Heinrich Ulbricht Jan 18 '22 at 15:08
  • 1
    @HeinrichUlbricht Yes, sorry, I can only speak to Javascript. I have had less luck with other languages like Python. – James Shapiro Jan 18 '22 at 15:20
  • @JamesShapiro Thanks for the feedback. Yeah, not your fault :D But after hours of tinkering I'm a bit frustrated. At least I now know why a colleague did log everything with "Information" level... – Heinrich Ulbricht Jan 18 '22 at 16:38
10

Microsoft keep changing the interface so many of these answers no longer are correct.

The best way I have found to view the logs is to go into Application Insights for the function itself and then search for some text that might be in the log in Transaction search.

Matthew
  • 1,630
  • 1
  • 14
  • 19
7

Azure Portal was updated last week and they moved logs from Monitor to the home of the actual Azure Function. However, to see them you need to click Test. I raised an issue with Microsoft support and they spent several days twiddling their thumbs before I came across the answer myself. I hope this saves others a bit of time

enter image description here

wpqs
  • 657
  • 1
  • 7
  • 18
  • I have a similar issue, whereby my function logs do not show (in Kudu or live stream), unless i go into the portal and click run, then subsequent logs show. Is this in line with your experience? Did anything come of your discussions with support? – gorillapower Jul 04 '18 at 07:46
  • I found that functions need not be run this way to show in the Logs. For example, I was running a time-triggered funciton, and as long as I'm looking at the Log console at the time of execution I get to see the logged message, without clicking "Run." – John VanZwieten Apr 23 '19 at 20:33
7

Log messages should show under the function code, if you're watching that window at the time of the function's execution: Log window under function code

To view log messages made while you weren't looking, you'll need Application Insights configured. If that's configured, that should show under the Monitor tab: Monitor Tab with past log entries.

John VanZwieten
  • 427
  • 4
  • 12
0

Indeed, the Logs section of the Function App in the Azure portal seems fragile. I had it open a few ours unused and then it did not log anything anymore. Closing the Function App and reopening it solved the problem.

Nils Breitmann
  • 647
  • 1
  • 4
  • 16
0

If you use Visual Studio Code and the Azure Functions Extension (link) you can directly connect to the log stream of the function:

Connect to log stream option

It will open an output window where you can see all the logs.

EDIT:

To get to this point you will have to go through the Azure Functions Extension tab and then select your subscription which will have whichever functions you have.

Selection steps

LoyalPotato
  • 401
  • 4
  • 15
0

In my case, right click on Function App and Refresh

HAL9000
  • 3,562
  • 3
  • 25
  • 47
-1

I would entirely avoid waiting for the logs to appear in the function app. Go over to Monitor on the left and go through it that way. Even then though there can be a solid 5 minute delay on them coming through. How on earth can aws be the only provider in this space that's able to give you logs immediately? GCP is bad for it as well.. (not sure about alicloud)

rlou
  • 498
  • 4
  • 16
  • FYI, you can generally find real-time logs in Application Insights if you enable it (you may also need to add the "logging" section to the host.json per my response above). I agree that it's more of a hassle compared to viewing CloudWatch logs, but Azure does actually do a decent job here. – James Shapiro Apr 09 '20 at 23:58