Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More advanced log configuration #4405

Open
ThomasArdal opened this issue May 10, 2019 · 15 comments
Open

More advanced log configuration #4405

ThomasArdal opened this issue May 10, 2019 · 15 comments
Labels

Comments

@ThomasArdal
Copy link

Microsoft.Azure.Functions.Extensions brought us the first attempt of being able to configure custom logging providers in Functions. With the current solution (where I can inject an ILoggerProvider), I can configure functions to log everything to a single log output. I would like to be able to do much more advanced logging configuration, though. Being able to register multiple logging provider, decide which log levels goes into which logs, and other features like that, is an essential part of most applications today.

Ideally, logging would be configured like any other application using Microsoft.Extensions.Logging:

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            ...
            builder.Services.AddLogging(logging =>
            {
                logging.AddConfiguration(config.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
                logging.AddEventSourceLogger();
            });
        }
    }
}
@alrod
Copy link
Member

alrod commented May 24, 2019

We do not have plans to support custom logging providers in functions currently. @fabiocav, correct me if I am not right.

@fabiocav
Copy link
Member

That is actually supported with the new DI capabilities.
The documentation here shows the explicit registration of a logger provider: https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection

We're working on more detailed documentation for this scenario

@ThomasArdal
Copy link
Author

@fabiocav It's perfectly fine to close this issue if it isn't something you are planning to work on. But for future views on this issue, I just want to point out that logging as described in the original question isn't supported with the current DI capabilities. Unless I've misunderstood something, you can only register a logger provider but not actually log to multiple locations, configure which log levels goes where, and all of the other features of Microsoft.Extensions.Logging.

@fabiocav
Copy link
Member

@ThomasArdal that's fair. A lot of what you've mentioned above is supported and we're lacking documentation on how to do that with what is currently exposed. Can you clarify your distinction between registering a logger provider and logging to multiple locations?

I'll reopen that as requested so we can track the documentation updates and any other potential work.

@fabiocav fabiocav reopened this May 28, 2019
@fabiocav fabiocav modified the milestones: Active Questions, Triaged May 28, 2019
@ThomasArdal
Copy link
Author

@fabiocav Great. I'll look out for the documentation. I was looking to do something like this, which either isnt't supported or I cannot get to work:

builder.Services.AddLogging(logging =>
{
    logging.AddConfiguration(config.GetSection("Logging"));
    logging.AddConsole();
    logging.AddDebug();
    logging.AddEventSourceLogger();
});

@kemmis
Copy link

kemmis commented May 30, 2019

Same here... can anyone show how to accomplish what @ThomasArdal is trying to do? Currently my logging is only going into app insights, but doesn't show up in the azure portal log window. I only see the built-in messages.

@ryanspletzer
Copy link

Not to pile up on this issue, but I know that a function will accept an ILogger in its method params and Azure Functions will provide it, but if another injected service wants an ILogger what is the best way to get that instance to it?

I am fine with the app insights-based ILogger instance being provided to the function method params to be provided elsewhere, but it seems that if I create and register a service with a dependency on ILogger it doesn't get that same instance.

@ryanspletzer
Copy link

Sorry I just noticed someone had posted about this over on the extensions repo where the DI extension lives: Azure/azure-functions-dotnet-extensions#10

@ThomasArdal
Copy link
Author

Any news on an example using custom logging from Azure Functions?

@ThomasArdal
Copy link
Author

@fabiocav This issue can be closed (IMO). I got this working by changing the way my ILoggerProvider is registered.

For anyone else interested in seeing how to configure a custom ILoggerProvider with Azure Functions, there's a sample available here: https://github.com/elmahio/Elmah.Io.Extensions.Logging/tree/master/samples/Elmah.Io.Extensions.Logging.Function.

@kemmis
Copy link

kemmis commented Dec 27, 2019

One thought - if we haven't added more detailed examples in the project / documentation on MS docs, then perhaps we can take several of the ones listed in this issue (as well as the IConfiguration issue I started), and put them in the project where most devs go to look?

@ThomasArdal
Copy link
Author

Some extended documentation would be nice. Also, if there are some additional requirements for how to implement a new ILoggerProvider in order for it to work with Functions, it would be nice to write them somewhere. I don't know if my provider was just implemented poorly, but it worked with both console and ASP.NET Core in the old version. So, something definitely works differently there when including it in Functions.

@kemmis
Copy link

kemmis commented Dec 27, 2019

Maybe someone around here can point us in the right direction of how to make this happen. Can we get one or two new issues created and label them as required documentation tasks. Then there we can discuss proper examples, and eventually get pull requests made out of them.

@ThomasArdal
Copy link
Author

Good idea. I think this issue should be closed once the new issues have been created. This issue signals that custom providers aren't supported, which is not the case 😄

@fabiocav
Copy link
Member

Thank you, all!

Will leave this open and flag this for follow up with @jeffhollan so we can prioritize documentation.

@fabiocav fabiocav added the docs label Dec 27, 2019
@fabiocav fabiocav removed this from the Triaged milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants