Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 003e20d

Browse files
committed
Fix issue with Azure listener incorrectly being registered
1 parent b1433d3 commit 003e20d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ static async Task<int> Main(string[] args)
6666

6767
builder.AddMiddleware(async (ic, next) =>
6868
{
69-
var op = ic.GetHost().Services.GetService<IOptions<ExtraOptions>>();
69+
var op = ic.GetHost().Services.GetService<IOptions<ExtraOptions>>()?.Value;
7070
// Show Azure Identity logs if the --debug option is set
71-
using AzureEventSourceListener? listener = AzureEventSourceListener.CreateConsoleLogger(op?.Value?.DebugEnabled == true ? EventLevel.LogAlways : EventLevel.Warning);
71+
using AzureEventSourceListener? listener = op?.DebugEnabled == true ? AzureEventSourceListener.CreateConsoleLogger(EventLevel.LogAlways) : null;
7272
await next(ic);
7373
});
7474
builder.AddMiddleware(async (ic, next) =>
@@ -201,8 +201,9 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
201201
{
202202
logBuilder.SetMinimumLevel(LogLevel.Warning);
203203
// If a config is unavailable, troubleshoot using (ctx.Configuration as IConfigurationRoot)?.GetDebugView();
204-
var options = ctx.GetInvocationContext().BindingContext.GetService<IOptions<ExtraOptions>>()?.Value;
205-
if (options?.DebugEnabled == true)
204+
// At this point, the host isn't ready. Get the config option directly.
205+
var debugEnabled = ctx.Configuration.GetValue<bool>("Debug");
206+
if (debugEnabled == true)
206207
{
207208
logBuilder.AddFilter("Microsoft.Graph.Cli", LogLevel.Debug);
208209
}

0 commit comments

Comments
 (0)