Provide empty logger factory service.

This commit is contained in:
Chris Ross 2014-05-06 14:57:48 -07:00
parent 7c7efeda57
commit af38d26fe7
2 changed files with 24 additions and 0 deletions

View File

@ -15,6 +15,7 @@
// See the Apache 2 License for the specific language governing // See the Apache 2 License for the specific language governing
// permissions and limitations under the License. // permissions and limitations under the License.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Hosting.Builder; using Microsoft.AspNet.Hosting.Builder;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
@ -22,6 +23,7 @@ using Microsoft.AspNet.Hosting.Startup;
using Microsoft.AspNet.Security.DataProtection; using Microsoft.AspNet.Security.DataProtection;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting
{ {
@ -47,6 +49,9 @@ namespace Microsoft.AspNet.Hosting
yield return describer.Transient<ITypeActivator, TypeActivator>(); yield return describer.Transient<ITypeActivator, TypeActivator>();
// TODO: We expect this to be provide by the runtime eventually.
yield return describer.Instance<ILoggerFactory>(new NullLoggerFactory());
yield return new ServiceDescriptor yield return new ServiceDescriptor
{ {
ServiceType = typeof(IContextAccessor<>), ServiceType = typeof(IContextAccessor<>),
@ -69,5 +74,23 @@ namespace Microsoft.AspNet.Hosting
yield return describer.Instance<IDataProtectionProvider>(DataProtectionProvider.CreateFromDpapi()); yield return describer.Instance<IDataProtectionProvider>(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<object, Exception, string> formatter)
{
return false;
}
}
} }
} }

View File

@ -7,6 +7,7 @@
"Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*", "Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*",
"Microsoft.Framework.ConfigurationModel": "0.1-alpha-*", "Microsoft.Framework.ConfigurationModel": "0.1-alpha-*",
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*",
"Microsoft.Framework.Logging": "0.1-alpha-*",
"Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*" "Microsoft.Net.Runtime.Interfaces": "0.1-alpha-*"
}, },
"configurations": { "configurations": {