Registering standard LoggerFactory : ILoggerFactory implementation

This commit is contained in:
Louis DeJardin 2014-08-15 15:42:01 -07:00
parent 58468e9509
commit c720364d0e
2 changed files with 7 additions and 35 deletions

View File

@ -51,8 +51,8 @@ namespace Microsoft.AspNet.Hosting
yield return describer.Instance<IApplicationLifetime>(new ApplicationLifetime());
// TODO: We expect this to be provide by the runtime eventually.
yield return describer.Instance<ILoggerFactory>(new NullLoggerFactory());
// TODO: Do we expect this to be provide by the runtime eventually?
yield return describer.Singleton<ILoggerFactory, LoggerFactory>();
yield return new ServiceDescriptor
{
@ -76,38 +76,5 @@ namespace Microsoft.AspNet.Hosting
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;
}
public IDisposable BeginScope(object state)
{
return NullScope.Instance;
}
}
private class NullScope : IDisposable
{
public static NullScope Instance = new NullScope();
public void Dispose()
{
// intentionally does nothing
}
}
}
}

View File

@ -36,5 +36,10 @@ namespace Microsoft.AspNet.TestHost
{
get { return new FrameworkName(".NETFramework", new Version(4, 5)); }
}
public string Configuration
{
get { return "Test"; }
}
}
}