diff --git a/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs b/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs
index 19efce0504..d87b404537 100644
--- a/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs
+++ b/src/Components/WebAssembly/Build/test/RuntimeDependenciesResolverTest.cs
@@ -56,7 +56,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
"Microsoft.Extensions.FileProviders.Abstractions.dll",
"Microsoft.Extensions.FileProviders.Physical.dll",
"Microsoft.Extensions.FileSystemGlobbing.dll",
+ "Microsoft.Extensions.Logging.dll",
"Microsoft.Extensions.Logging.Abstractions.dll",
+ "Microsoft.Extensions.Options.dll",
"Microsoft.Extensions.Primitives.dll",
"Microsoft.JSInterop.dll",
"Microsoft.JSInterop.WebAssembly.dll",
diff --git a/src/Components/WebAssembly/WebAssembly/src/Hosting/LoggingBuilder.cs b/src/Components/WebAssembly/WebAssembly/src/Hosting/LoggingBuilder.cs
new file mode 100644
index 0000000000..66c2190451
--- /dev/null
+++ b/src/Components/WebAssembly/WebAssembly/src/Hosting/LoggingBuilder.cs
@@ -0,0 +1,18 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
+{
+ internal class LoggingBuilder : ILoggingBuilder
+ {
+ public LoggingBuilder(IServiceCollection services)
+ {
+ Services = services;
+ }
+
+ public IServiceCollection Services { get; }
+ }
+}
diff --git a/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs b/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs
index f5d803c3b8..0a60896f3e 100644
--- a/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs
+++ b/src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs
@@ -55,6 +55,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
Configuration = new ConfigurationBuilder();
RootComponents = new RootComponentMappingCollection();
Services = new ServiceCollection();
+ Logging = new LoggingBuilder(Services);
+
+ Logging.SetMinimumLevel(LogLevel.Warning);
// Retrieve required attributes from JSRuntimeInvoker
InitializeNavigationManager(jsRuntimeInvoker);
@@ -128,6 +131,11 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
///
public IWebAssemblyHostEnvironment HostEnvironment { get; }
+ ///
+ /// Gets the logging builder for configuring logging services.
+ ///
+ public ILoggingBuilder Logging { get; }
+
///
/// Registers a instance to be used to create the .
///
@@ -186,8 +194,9 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
Services.AddSingleton(DefaultWebAssemblyJSRuntime.Instance);
Services.AddSingleton(WebAssemblyNavigationManager.Instance);
Services.AddSingleton(WebAssemblyNavigationInterception.Instance);
- Services.AddSingleton();
- Services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(WebAssemblyConsoleLogger<>)));
+ Services.AddLogging(builder => {
+ builder.AddProvider(new WebAssemblyConsoleLoggerProvider(DefaultWebAssemblyJSRuntime.Instance));
+ });
}
}
}
diff --git a/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj b/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj
index c543a7a11b..8b6c508893 100644
--- a/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj
+++ b/src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLogger.cs b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLogger.cs
index 51fe7536ea..668aeb7c96 100644
--- a/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLogger.cs
+++ b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLogger.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Collections.Concurrent;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
@@ -43,7 +44,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Services
public bool IsEnabled(LogLevel logLevel)
{
- return logLevel >= LogLevel.Warning && logLevel != LogLevel.None;
+ return logLevel != LogLevel.None;
}
public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter)
diff --git a/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLoggerProvider.cs b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLoggerProvider.cs
new file mode 100644
index 0000000000..c79b3f07b0
--- /dev/null
+++ b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLoggerProvider.cs
@@ -0,0 +1,45 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Collections.Concurrent;
+using Microsoft.Extensions.Logging;
+using Microsoft.JSInterop;
+
+namespace Microsoft.AspNetCore.Components.WebAssembly.Services
+{
+ ///
+ /// A provider of instances.
+ ///
+ internal class WebAssemblyConsoleLoggerProvider : ILoggerProvider
+ {
+ private readonly ConcurrentDictionary> _loggers;
+ private readonly IJSInProcessRuntime _jsRuntime;
+ private bool _disposed;
+
+ ///
+ /// Creates an instance of .
+ ///
+ /// The options to create instances with.
+ public WebAssemblyConsoleLoggerProvider(IJSInProcessRuntime jsRuntime)
+ {
+ _loggers = new ConcurrentDictionary>();
+ _jsRuntime = jsRuntime;
+ }
+
+ ///
+ public ILogger CreateLogger(string name)
+ {
+ return _loggers.GetOrAdd(name, loggerName => new WebAssemblyConsoleLogger