在我的API项目中,Startup.cs文件我有以下内容:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseMvc();
loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection(),
(logLevel, message, exception) => $"[{DateTime.UtcNow}] {logLevel}: {message}");
这适用于API项目。我如何在Structuremap容器中注册它?
var container = new StructureMap.Container(
c =>
{
c.For(typeof(ILogger<>)).Use(typeof(Logger<>));
c.For<ILoggerFactory>..../// use what?
}
答案 0 :(得分:1)
如果我理解正确,您需要注册loggerFactory
的现有实例。有Use
方法的重载需要现有实例:
var container = new StructureMap.Container(
c =>
{
c.For(typeof(ILogger<>)).Use(typeof(Logger<>));
c.For(typeof(ILoggerFactory)).Use(loggerFactory);
});
有关详细信息,请参阅Registering Existing Objects。