1818using Microsoft . Extensions . Hosting ;
1919using Microsoft . Extensions . Logging ;
2020using Npgsql . EntityFrameworkCore . PostgreSQL . Infrastructure ;
21+ using Serilog ;
2122using System ;
2223using System . Collections ;
2324using System . Collections . Generic ;
@@ -30,7 +31,19 @@ public class Program
3031 {
3132 public static void Main ( string [ ] args )
3233 {
33- CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
34+ LoggingService . ConfigurarBasicStartupSerilog ( ) . CreateBootstrapLogger ( ) ;
35+ try
36+ {
37+ CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
38+ }
39+ catch ( Exception ex )
40+ {
41+ Log . Fatal ( ex , "Error fatal durante el arranque" ) ;
42+ }
43+ finally
44+ {
45+ Log . CloseAndFlush ( ) ; // asegura que se escriben todos los logs pendientes
46+ }
3447 }
3548
3649 public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
@@ -42,12 +55,11 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
4255 config . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true ) ;
4356 config . AddJsonFile ( $ "appsettings.{ hostContext . HostingEnvironment . EnvironmentName } .json", optional : true , reloadOnChange : true ) ;
4457 } )
58+ . UseSerilog ( ( context , services , configuration ) => LoggingService . ConfigurarSerilog ( context . Configuration , services , configuration ) )
4559 . ConfigureServices ( ( hostContext , services ) =>
4660 {
4761 IConfiguration configuration = hostContext . Configuration ;
4862
49- LoggingService . ConfigurarLogging ( services , configuration ) ;
50-
5163 AppContext . SetSwitch ( "Npgsql.EnableLegacyTimestampBehavior" , true ) ;
5264 services . AddScoped ( typeof ( UtilTelemetry ) ) ;
5365 services . AddScoped ( typeof ( Usuario ) ) ;
0 commit comments