Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Not seeing ILogger logs in Dashboard #1716

Open brettsam opened 6 years ago

brettsam commented 6 years ago

From @tourili here: https://github.com/Azure/azure-functions-core-tools/issues/130#issuecomment-391115370

I don't know if what I am experiencing is related to this issue:

Create a webjob console project (using Microsoft.Azure.WebJobs 2.2.0) in my "function" I add ILogger parameter using that logger bunch of targets work well (Console file etc...) Except that nothing is written in the azure dashboard or kudu console. Looks like the TraceWriter is not involved at all when logging events using the ILogger parameter:

    [FunctionName("run-function")]
    public async Task RunAsync([QueueTrigger("request-run-function")] Section sectionRequest, ILogger logger, CancellationToken token)
brettsam commented 6 years ago

@tourili -- can you show me how you're configuring your WebJob? The JobHostConfiguration, etc, in Program.cs?

tourili commented 6 years ago

For sure in Program.cs

var config = new JobHostConfiguration();
....
loggerFactory = new LoggerFactory();
loggerFactory.AddConsole();
config.LoggerFactory = loggerFactory;
var host = new JobHost(config);
host.RunAndBlock();

In my function class file I have :

[FunctionName("run-function")]
public async Task RunAsync([QueueTrigger("request-run-function")] Section sectionRequest, ILogger logger, CancellationToken token)
{
logger.LogInformation($"This is a log information for {sectionRequest.Id}");
...
}

My log "This is a log information for ..." appears OK on the local console, but never on the azure webjob dashboard

brettsam commented 6 years ago

It looks like this doesn't work in v2.x. I remember that I had to do some interesting stuff to get this to work in v3.x, but we should be able to back-port it fairly easily. I'll clear the Milestone so we can re-triage this.

@tourili -- I don't think we have many people that converge on using both ILogger and the dashboard, which may be why this hasn't come up previously. For now, if you need dashboard logging, you'll need to use a TraceWriter or you can switch to Application Insights for your logging, which works for both ILogger and TraceWriter.

aderderian commented 6 years ago

Still seeing this issue in Azure Functions beta. Would be great to get this resolved. Any updates?

paulbatum commented 6 years ago

To be transparent, I am not sure if we're going to fix this (thats why its in the unknown milestone). Our guidance is that if you want to use ILogger, move to using App Insights as its a much richer offering anyway.

aderderian commented 6 years ago

@paulbatum you won't fix the trace with ILogger or adding DI support for Logger ? I find the trace logger easier to follow than AI sometimes due to the latency of AI.

ggirard07 commented 6 years ago

App Insights might be a richer offering, but it is also a much more complicated offering in the case you simply want some logs. Looks like the good old Microsoft which wants you to use all of its services...

ILogger is now the way to go for logging in .Net Core. By forcing people to use TraceWriter you are keeping us away of the standard track.

aderderian commented 6 years ago

Also everything I have read says to use ILogger so that if you're using Application Insights you can filter by category. Then trying to reuse your service classes with Azure Functions, this breaks that convention.

paulbatum commented 6 years ago

@aderderian this issue is about using ILogger + Dashboard. Thats what I was referring to. In regards to App Insights latency, one good solution is to use their "live metrics" view. It shows a real-time stream of log messages and saves you from having to wait for log messages to appear in app insights. In regards to your last comment, I don't understand, you'll need to explain in more detail.

@ggirard07 in the same way that ILogger is the go-to solution for logging on .NET Core, App Insights is the go-to solution for application logging in Azure. It simply does not feel worthwhile to us to spend time making old stuff (the dashboard) work with newer stuff (ILogger) when there are so many other issues and features we could be spending our time on instead.

aderderian commented 6 years ago

@paulbatum Basically this thread over here : https://github.com/Azure/azure-functions-host/issues/1579#issuecomment-411862259

It seems best practice to user ILogger and not ILogger. It would be nice to be able to have a LoggerFactory in Azure Functions in order to instantiate ILogger to pass into service methods.

paulbatum commented 6 years ago

Its best practice to use ILogger and App Insights. That issue you linked to is valid but I don't see how its related to the dashboard scenario that is being discussed here.

ggirard07 commented 6 years ago

@paulbatum We share common libraries between our webjobs, webapi and desktop apps. Those library have to support ILogger for WebAPI and desktop compatibility. Webjobs is the only implementation out of the track here...

brettsam commented 6 years ago

Going back to the original issue: "ILogger logs do not show up in dashboard":

@aderderian, you said above

Still seeing this issue in Azure Functions beta. Would be great to get this resolved. Any updates?

I want to dive into that a bit more. I see it working for me, so I'd like to figure out why it's not working for you. Can you share exactly what you're doing and not seeing the logs from your ILogger in the dashboard?

I just tried this on a Function app 2.0.11946.0 (beta):

using System.Net;

public static Task<HttpResponseMessage> Run(HttpRequestMessage req, ILogger log)
{
    log.LogInformation($"I just made this request: {DateTime.UtcNow}");
    return Task.FromResult(new HttpResponseMessage());
}

And when I look at my WebJobs dashboard: image

aderderian commented 6 years ago

I will take a look asap. I had to refactor service layer to take ILogger versus ILogger. I will do a test asap and report back.

paulbatum commented 6 years ago

@aderderian One thing I don't understand is that in a couple of your comments you've said "ILogger vs ILogger":

It seems best practice to user ILogger and not ILogger.

I had to refactor service layer to take ILogger versus ILogger.

What do you mean by this?

aderderian commented 6 years ago

Sorry, typo @paulbatum . I meant to say it seems best practice to use ILogger and not just ILogger in a service layer.

paulbatum commented 6 years ago

I'm still struggling to understand... is it possible you mean to be saying ILogger vs ILogger<T> and the <T> is being removed by githubs formatting?

aderderian commented 6 years ago

Haha, yes you're right. Ilogger<T> is what I was typing. Sorry I did not see it being removed.

ggirard07 commented 6 years ago

@brettsam just updated to v3 and I can see some logs in output window as you shown on your screenshot. Problem is functions seem to be no longer detected and logs are no longer classified by execution as it used to be. Some example of the behavior from v2 I am looking for:

image

image

image

Are those breaking changes expected?

brettsam commented 6 years ago

We're pushing people to use App Insights now, so the dashboard isn't wired up by default.

How are you configuring your host? Have you called AddDashboardLogging() in the call to ConfigureWebJobs?

        var builder = new HostBuilder()
            .UseEnvironment("Development")
            .ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices()
                .AddAzureStorage()
                .AddDashboardLogging(); // This is deprecated, but should still work
            });
ggirard07 commented 6 years ago

@brettsam yes I did and noticed the obsolete warning.

var builder = new HostBuilder()
    .UseEnvironment(aspCoreConfig[HostDefaults.EnvironmentKey] ?? EnvironmentName.Production)
    .ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddDashboardLogging();
        b.AddAzureStorage();
    })

We don't want to move to app insight currently as it has a lot of considerations we need to go through. I understand it is a really powerful solution but if we move to it we would like to migrate our entire system, not just a single webjob. The scope is not the same in that case.

leemcmullen commented 5 years ago

Even with b.AddDashboardLogging(); added, I still can't get the dashboard function specific logging working. I assume I'm having the same issue as the OP on issue 1962.

Has anyone else experienced this and if so, is there a way to get dashboard logging working on v3?

paulbatum commented 5 years ago

@leemcmullen The dashboard does not work with webjobs v3. See my comment here: https://github.com/Azure/azure-webjobs-sdk/issues/2179#issuecomment-485555607

I acknowledge this is contrary to some of the comments made earlier in this issue.

Unfortunately, we forgot to remove the .AddDashboardLogging() method prior to the GA release. We'll be doing so in the next major version update.