From af38d26fe74a0a04b3e38934a2118296b03e0f0b Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 6 May 2014 14:57:48 -0700 Subject: [PATCH] Provide empty logger factory service. --- .../HostingServices.cs | 23 +++++++++++++++++++ src/Microsoft.AspNet.Hosting/project.json | 1 + 2 files changed, 24 insertions(+) diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 2ce566dbeb..c7376cd52e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -15,6 +15,7 @@ // See the Apache 2 License for the specific language governing // permissions and limitations under the License. +using System; using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Server; @@ -22,6 +23,7 @@ using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Security.DataProtection; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Hosting { @@ -47,6 +49,9 @@ namespace Microsoft.AspNet.Hosting yield return describer.Transient(); + // TODO: We expect this to be provide by the runtime eventually. + yield return describer.Instance(new NullLoggerFactory()); + yield return new ServiceDescriptor { ServiceType = typeof(IContextAccessor<>), @@ -69,5 +74,23 @@ namespace Microsoft.AspNet.Hosting yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); } } + + // TODO: Temp workaround until the runtime reliably provides logging. + // If ILoggerFactory is never guaranteed, move this fallback into Microsoft.AspNet.Logging. + private class NullLoggerFactory : ILoggerFactory + { + public ILogger Create(string name) + { + return new NullLogger(); + } + } + + private class NullLogger : ILogger + { + public bool WriteCore(TraceType eventType, int eventId, object state, Exception exception, Func formatter) + { + return false; + } + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Hosting/project.json b/src/Microsoft.AspNet.Hosting/project.json index 70308d391e..bc7d383d2d 100644 --- a/src/Microsoft.AspNet.Hosting/project.json +++ b/src/Microsoft.AspNet.Hosting/project.json @@ -7,6 +7,7 @@ "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*", + "Microsoft.Framework.Logging": "0.1-alpha-*", "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" }, "configurations": {