В стартовом проекте WebApi вводятся три провайдера логгера:
- DebugLoggerProvider
- ConsoleLoggerProvider
- ApplicationInsightsLoggerProvider
В указанном проекте DataAccess вводятся только два провайдера регистратора:
- DebugLoggerProvider
- ConsoleLoggerProvider
Кто-нибудь знает, почему не существует ApplicationInsightsLoggerProvider, внедренного за пределы проекта WebApi?
Program.cs:
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(config =>
{
config.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
})
.ConfigureLogging(factory =>
{
factory.AddConsole();
factory.AddDebug();
factory.AddAzureWebAppDiagnostics();
})
.UseStartup<Startup>()
.Build();
}
Startup.cs:
public Startup(IConfiguration configuration, IHostingEnvironment environment)
{
Configuration = configuration;
HostingEnvironment = environment;
}
public IConfiguration Configuration { get; }
public IHostingEnvironment HostingEnvironment { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Information);
app.UseMvc();
}
appsettings.json:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
}
}
}
appsettings.dev.json:
"ApplicationInsights": {
"InstrumentationKey": "......."
}
TestController.cs -> проект WebApi (добавляет DebugLoggerProvider, ConsoleLoggerProvider и ApplicationInsightsLoggerProvider в регистратор):
private readonly Microsoft.Extensions.Logging.ILogger<TestController> _logger;
public TestController(ILogger<TestController> logger)
{
_logger = logger; // Contains DebugLoggerProvider, ConsoleLoggerProvider and ApplicationInsightsLoggerProvider
}
TestRepository.cs -> Проект DataAccess (только вводит DebugLoggerProvider, ConsoleLoggerProvider в регистратор):
private readonly Microsoft.Extensions.Logging.ILogger<TestRepository> _logger;
public TestRepository(ILogger<TestRepository> logger)
{
_logger = logger; // Contains DebugLoggerProvider, ConsoleLoggerProvider
}