Open brettsam opened 6 years ago
@tourili -- can you show me how you're configuring your WebJob? The JobHostConfiguration, etc, in Program.cs?
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
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
.
Still seeing this issue in Azure Functions beta. Would be great to get this resolved. Any updates?
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.
@paulbatum you won't fix the trace with ILogger or adding DI support for Logger
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.
Also everything I have read says to use ILogger
@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.
@paulbatum Basically this thread over here : https://github.com/Azure/azure-functions-host/issues/1579#issuecomment-411862259
It seems best practice to user ILogger
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.
@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...
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:
I will take a look asap. I had to refactor service layer to take ILogger versus ILogger
@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?
Sorry, typo @paulbatum . I meant to say it seems best practice to use ILogger
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?
Haha, yes you're right. Ilogger<T>
is what I was typing. Sorry I did not see it being removed.
@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:
Are those breaking changes expected?
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
});
@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.
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?
@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.
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: