fix issue #I3QBZI

This commit is contained in:
yubaolee 2021-05-09 00:02:28 +08:00
parent 88e2015a11
commit cd211c05d3
2 changed files with 4 additions and 28 deletions

View File

@ -1,24 +0,0 @@

using Microsoft.Extensions.Logging;
namespace Infrastructure
{
/// <summary>
/// 从3.0开始Startup ConfigureServices中不能使用ILogger需要扩展
/// </summary>
public class StartupLogger
{
private readonly ILogger<StartupLogger> _logger;
public StartupLogger(ILogger<StartupLogger> logger)
{
_logger = logger;
}
public void LogInformation(string message)
{
_logger.LogInformation(message);
}
}
}

View File

@ -30,12 +30,12 @@ namespace OpenAuth.Mvc
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddSingleton(provider => //在startup中需要强制创建log4net
var loggerFactory = LoggerFactory.Create(builder =>
{ {
var service = provider.GetRequiredService<ILogger<StartupLogger>>(); builder.AddLog4Net();
return new StartupLogger(service);
}); });
var logger = services.BuildServiceProvider().GetRequiredService<StartupLogger>(); ILogger logger = loggerFactory.CreateLogger<Startup>();
var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value; var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;
if (!string.IsNullOrEmpty(identityServer)) if (!string.IsNullOrEmpty(identityServer))
{ {