Vijay
Vijay

Reputation: 446

How to access Azure Webjobs log using C#

I have a azure webjob running on a scheduled basis and I need to access the run logs and the output of each run.

I bumped into kudu api, but couldn't go any further as I was not sure which credentials to pass with my web request.

Sample Code:

private static void GetAPIData2()
    {
        String Url = "https://MyWebsite.scm.azurewebsites.net/azurejobs/api/jobs";
        WebRequest request = WebRequest.Create(Url);

        request.ContentType = "application/json";
        request.Method = "GET";

        //Your Azure FTP deployment credentials here
        request.Credentials = new NetworkCredential("What should go here?", "and here?");

        WebResponse response = request.GetResponse();
        Console.WriteLine(response.ToString());
    }

I get 401 Unauthorized if use my azure administrator account.

What username and password should I use to authenticate?

Upvotes: 0

Views: 1209

Answers (3)

alex
alex

Reputation: 335

it is not directly related to the answer but I've also found that in PowerShell it is possible to call WebJobs API with Bearer token fetched from Get-AzAccessToken cmdlet:

$token = Get-AzAccessToken
$token.Token

(didn't find way yet to get it in C# but it is probably can be found by checking code of Get-AzAccessToken)

Upvotes: 0

Aaron Hoffman
Aaron Hoffman

Reputation: 6962

You could also potentially use a custom TraceWriter. Example here: https://gist.github.com/aaronhoffman/3e319cf519eb8bf76c8f3e4fa6f1b4ae

Upvotes: 0

David Ebbo
David Ebbo

Reputation: 43203

Please take a look at this page to understand the kind of credentials that you can pass to these APIs.

Upvotes: 4

Related Questions