我目前正在尝试创建一个Logger,这样我就可以将它注入到单元测试中。我在跟踪https://stackoverflow.com/a/43425633/1057052,它过去很管用!然后我移动了项目并重新建立了依赖关系,现在我得到了
'ServiceCollection‘不包含'AddLogging’的定义,也找不到接受'ServiceCollection‘类型的第一个参数的可访问扩展方法'AddLogging’(您缺少使用指令还是程序集引用?)
我一定是错过了什么愚蠢的东西。目前在ASP.NET Core2.2下,我相信我已经分配了正确的依赖项。
在过去的一小时里,我一直在重新安装我们的so!找不出问题是什么
下面是代码:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Planificacion.UnitTest.Config
{
public class LoggerTestConfig
{
private LoggerTestConfig()
{
}
// https://stackoverflow.com/a/43425633/1057052
public static ILogger<T> GetLoggerConfig<T>() where T : class
{
var serviceProvider = new ServiceCollection()
.AddLogging()
.BuildServiceProvider();
var factory = serviceProvider.GetService<ILoggerFactory>();
return factory.CreateLogger<T>();
}
}
}

发布于 2019-01-22 21:53:35
该图像突出显示引用了依赖项注入dll,但所需的LoggingServiceCollectionExtensions.AddLogging法 (如所提供的链接所示)指示
Namespace: Microsoft.Extensions.DependencyInjection
Assembly: Microsoft.Extensions.Logging.dll <----NOTE THIS它没有像图像中所示的那样被引用。
添加对上述Microsoft.Extensions.Logging.dll程序集的引用。
https://stackoverflow.com/questions/54316380
复制相似问题