mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 14:04:41 +08:00
fix issue #I3QBZI
This commit is contained in:
parent
88e2015a11
commit
cd211c05d3
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user