From cd211c05d37f59ccac7c2c73ac49f8387d4c0dd4 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Sun, 9 May 2021 00:02:28 +0800 Subject: [PATCH] fix issue #I3QBZI --- Infrastructure/StartupLogger.cs | 24 ------------------------ OpenAuth.Mvc/Startup.cs | 8 ++++---- 2 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 Infrastructure/StartupLogger.cs diff --git a/Infrastructure/StartupLogger.cs b/Infrastructure/StartupLogger.cs deleted file mode 100644 index 583ce3db..00000000 --- a/Infrastructure/StartupLogger.cs +++ /dev/null @@ -1,24 +0,0 @@ - - -using Microsoft.Extensions.Logging; - -namespace Infrastructure -{ - /// - /// 从3.0开始Startup ConfigureServices中不能使用ILogger,需要扩展 - /// - public class StartupLogger - { - private readonly ILogger _logger; - - public StartupLogger(ILogger logger) - { - _logger = logger; - } - - public void LogInformation(string message) - { - _logger.LogInformation(message); - } - } -} \ No newline at end of file diff --git a/OpenAuth.Mvc/Startup.cs b/OpenAuth.Mvc/Startup.cs index 47409f2d..df87fda9 100644 --- a/OpenAuth.Mvc/Startup.cs +++ b/OpenAuth.Mvc/Startup.cs @@ -30,12 +30,12 @@ namespace OpenAuth.Mvc // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddSingleton(provider => + //在startup中需要强制创建log4net + var loggerFactory = LoggerFactory.Create(builder => { - var service = provider.GetRequiredService>(); - return new StartupLogger(service); + builder.AddLog4Net(); }); - var logger = services.BuildServiceProvider().GetRequiredService(); + ILogger logger = loggerFactory.CreateLogger(); var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value; if (!string.IsNullOrEmpty(identityServer)) {