diff --git a/src/Backend/AutopilotMonitor.Functions/Program.cs b/src/Backend/AutopilotMonitor.Functions/Program.cs index 59a56e46..a0c6d63b 100644 --- a/src/Backend/AutopilotMonitor.Functions/Program.cs +++ b/src/Backend/AutopilotMonitor.Functions/Program.cs @@ -8,6 +8,7 @@ using Microsoft.Azure.Functions.Worker.Builder; using Microsoft.Azure.Functions.Worker.Middleware; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Microsoft.Identity.Web; var builder = FunctionsApplication.CreateBuilder(args); @@ -39,15 +40,16 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) { OnAuthenticationFailed = context => { - Console.WriteLine($"[Auth] Authentication failed: {context.Exception?.Message}"); + var logger = context.HttpContext.RequestServices.GetRequiredService().CreateLogger("Auth"); + logger.LogWarning("Authentication failed: {Error}", context.Exception?.Message); return Task.CompletedTask; }, OnTokenValidated = context => { + var logger = context.HttpContext.RequestServices.GetRequiredService().CreateLogger("Auth"); var claims = context.Principal?.Claims; var tenantId = claims?.FirstOrDefault(c => c.Type == "tid")?.Value; - var upn = claims?.FirstOrDefault(c => c.Type == "upn" || c.Type == "preferred_username")?.Value; - Console.WriteLine($"[Auth] Token validated for user: {upn}, tenant: {tenantId}"); + logger.LogDebug("Token validated for tenant: {TenantId}", tenantId); return Task.CompletedTask; } }; diff --git a/src/Shared/AutopilotMonitor.Shared/Models/UsageMetrics.cs b/src/Shared/AutopilotMonitor.Shared/Models/UsageMetrics.cs index 5690eb46..d35cb711 100644 --- a/src/Shared/AutopilotMonitor.Shared/Models/UsageMetrics.cs +++ b/src/Shared/AutopilotMonitor.Shared/Models/UsageMetrics.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic;