diff --git a/Surge365.MassEmailReact.API/Program.cs b/Surge365.MassEmailReact.API/Program.cs index 0151ce1..05ea68f 100644 --- a/Surge365.MassEmailReact.API/Program.cs +++ b/Surge365.MassEmailReact.API/Program.cs @@ -17,8 +17,6 @@ using Surge365.MassEmailReact.Infrastructure.EntityMaps; var builder = WebApplication.CreateBuilder(args); -builder.AddCustomConfigurationSources(); - WebApplication? app = null; try { @@ -45,37 +43,8 @@ try }; }); - builder.Services.AddHttpContextAccessor(); - - Factory.RegisterDefaultServices(builder.Services, - adminContextProvider: provider => - { - var httpContextAccessor = provider.GetRequiredService(); - var httpContext = httpContextAccessor.HttpContext; - - if (httpContext == null) - return new AdminContext(); - - string? adminId = null; - string? ipAddress = httpContext?.Connection?.RemoteIpAddress?.ToString(); - string? appVersion = httpContext?.Request.Headers["app-version"].ToString(); - string? deviceInfo = httpContext?.Request.Headers["User-Agent"].ToString(); - - if (httpContext?.User?.Identity?.IsAuthenticated == true) - { - adminId = httpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? httpContext.User.FindFirst("sub")?.Value; - } - - return new AdminContext - { - LoggedIn = !string.IsNullOrWhiteSpace(adminId), - AdminId = adminId, - IpAddress = ipAddress, - AppVersion = appVersion, - DeviceInfo = deviceInfo - }; - } - ); + Factory.RegisterDefaultServices(builder.Services); + builder.Services.AddHttpClient("SendGridClient", client => { @@ -130,9 +99,9 @@ try } catch (Exception ex) { - Console.WriteLine($"Error during application startup: {ex.Message}"); - LoggingService appLoggingService = new LoggingService(builder.Configuration, new DataAccessFactory(builder.Configuration)); - appLoggingService.LogError(ex).Wait(); + SurgeLoggerProvider surgeLoggerProvider = new SurgeLoggerProvider(builder.Configuration); + ILogger surgeLogger = surgeLoggerProvider.CreateLogger(typeof(Program).ToString()); + surgeLogger.LogError(ex, "An error occurred during application startup."); return; } if (app != null)