Esta documentación está en fase de desarrollo y puede contener errores.

Blazor Server Guidelines

Convenciones de arranque para apps Blazor Server con Dinaup, del banner inicial a la comprobación de red.

Application Startup Convention

Prerequisites

<PackageReference Include="Dinaup" Version="*" />

1. Startup Banner

Identifies if a startup failure is caused by Docker or the application itself.

Console.WriteLine("══════════════════════════════════════════════════════════════");
Console.WriteLine("  [APP_NAME] - Starting application");
Console.WriteLine($"  Date/Time: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
Console.WriteLine("══════════════════════════════════════════════════════════════");

2. Network Connectivity Check

Prevents firewall or network issues from causing errors in other services that are harder to diagnose.

while (await Dinaup.Extensions.CheckNetworkConnectivityAsync() == false)
{
    Console.WriteLine("[ERROR] No internet connection. Retrying in 1 second...");
    await Task.Delay(1000);
}

3. Debug Port

Prevents port conflicts with other apps during development. In production, ports are configured via environment variables.

const int DEBUG_PORT = 6114;

// Only applies when debugging
if (Debugger.IsAttached)
    builder.WebHost.UseUrls("http://*:" + DEBUG_PORT.ToString());

4. Version Endpoint

app.MapGet("/Version", () => Results.Ok(new 
{ 
    version = Assembly.GetExecutingAssembly().GetName().Version.ToString() 
}));

5. Fatal Error Handling

retryinitialization:

try
{
    var builder = WebApplication.CreateBuilder(args);
    
    if (Debugger.IsAttached)
        builder.WebHost.UseUrls("http://*:" + DEBUG_PORT.ToString());

    // ... initialization ...

    app.Run();
}
catch (Exception ex)
{
    Console.WriteLine("══════════════════════════════════════════════════════════════");
    Console.WriteLine("  [ERROR] Fatal error during initialization");
    Console.WriteLine($"  Message: {ex.Message}");
    Console.WriteLine($"  Type: {ex.GetType().Name}");
    Console.WriteLine($"  Date/Time: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
    Console.WriteLine("══════════════════════════════════════════════════════════════");
    Console.WriteLine(ex.ToString());

    try { Dinaup.Logs.Write_Flag("INI", ex); } catch { }

    var builderRecovery = WebApplication.CreateBuilder(args);
    
    if (Debugger.IsAttached)
        builderRecovery.WebHost.UseUrls("http://*:" + DEBUG_PORT.ToString());

    var appRecovery = builderRecovery.Build();
    appRecovery.UseMiddleware<ErrorFatalMiddleware>();
    
    Console.WriteLine("[LOG] Recovery mode. Retrying in 10 seconds...");
    using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
    await appRecovery.RunAsync(cts.Token);
    
    goto retryinitialization;
}
finally
{
    Dinaup.Logs.CloseAndFlush();
}

On this page