Skip to content

The usage in a blazor RC1 project breaks the NavigationManager  #9

Description

@alexfdezsauco

The usage in a blazor RC1 project breaks the NavigationManager.

How to reproduce:

  1. Assume that you have a service locator that resolve backed services. In this case the ingest backend.

Program.cs

    ....
    host = await host.RecreateLogAsync();
    try
    {
        await host.RunAsync();
    }
    catch (Exception ex)
    {
        Log.Fatal(ex, "An exception occurred while creating the web assembly host");
        throw;
    }

WebAssemblyHostExtensions.cs

public static class WebAssemblyHostExtensions
{
    public static async Task<WebAssemblyHost> RecreateLogAsync(this WebAssemblyHost @this)
    {
        return await @this.RecreateLogAsync(@this.Services.GetService<IServiceDiscovery>(), @this.Services.GetService<LoggingLevelSwitch>());
    }

    private static async Task<WebAssemblyHost> RecreateLogAsync(this WebAssemblyHost @this, IServiceDiscovery serviceDiscovery, LoggingLevelSwitch loggingLevelSwitch)
    {
        var configuration = new LoggerConfiguration()
            .MinimumLevel.ControlledBy(loggingLevelSwitch)
            .Enrich.WithProperty("Application", "MyApp")
            .WriteTo.BrowserConsole(levelSwitch: loggingLevelSwitch);

        try
        {
            var serviceEndPoint = await serviceDiscovery.GetServiceEndPoint("ingest");
            if (!string.IsNullOrWhiteSpace(serviceEndPoint))
            {
                var ingestUrl = serviceEndPoint.TrimEnd('/') + "/ingest";
                configuration = configuration.WriteTo.BrowserHttp($"{ingestUrl}", controlLevelSwitch: loggingLevelSwitch);
                Log.Information("Configured Log for with server side ingest '{IngestUrl}'", ingestUrl);
            }
            else
            {
                Log.Warning("Ingest server endpoint not found");
            }
        }
        catch (Exception e)
        {
            Log.Warning(e, "Error recreating Log for with server side ingest");
        }

        Log.Logger = configuration.CreateLogger();

        return @this;
    }
 }

Results:

The code above works but breaks the NavigationManager. When the NavigateTo is called, nothing happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions