Azure / Azure/azure-functions-host

Is it also possible to enable us to actually get a logger in the Startup? At some point we need to log more info during the startup and our only possibility is to create a logger manually by bypassing every previously added settings using the builder.

Open
#7,067 3 comments 2 reactions 0 assignees View on GitHub
Needs: Attention :wave:
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

Is it also possible to enable us to actually get a logger in the Startup? At some point we need to log more info during the startup and our only possibility is to create a logger manually by bypassing every previously added settings using the builder.

If we try to get a `ILogger`, that raised this following exception:

> System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.Azure.WebJobs.Script.IFileLoggingStatusManager' while attempting to activate 'Microsoft.Azure.WebJobs.Script.Diagnostics.HostFileLoggerProvider'.'

I'm aware that during the `Configure` not all dependencies are already there and more could be added later on. But this statement doesn't solve what everybody is always asking: have logging in the startup.

This is what we need to do to "fix" this issue:
```csharp
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
logger = loggerFactory.CreateLogger();
```

_Originally posted by @pellea in https://github.com/Azure/azure-functions-host/issues/5782#issuecomment-627788704_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the exception when resolving ILogger during Configure, then inspect how HostFileLoggerProvider depends on IFileLoggingStatusManager and how startup services are registered. Done means Startup can obtain a logger without manually creating a separate factory or bypassing previously configured settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.