// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Application Insightsへのログ出力設定 // // NOTE: https://docs.microsoft.com/ja-jp/azure/azure-monitor/app/asp-net-core#configuration-recommendation-for-microsoftapplicationinsightsaspnetcore-sdk-2150--above // //services.AddSingleton(typeof(ITelemetryChannel), new ServerTelemetryChannel() { StorageFolder = "/tmp/" }); //var telemetryConfigutaion = new TelemetryClientConfigure(Configuration.GetValue<string>("ApplicationInsights_InstrumentationKey")).aiOptions; //services.AddApplicationInsightsTelemetry(telemetryConfigutaion); string appInsightsKey = Configuration.GetValue <string>("ApplicationInsights_InstrumentationKey"); string logLevel = Configuration.GetValue <string>("Log_Level"); services = TelemetryClientConfigure.ConfigureServerTelemetryChannel(services, appInsightsKey); services = myILoggerProvider.Congfigure(services, appInsightsKey, logLevel); services.AddControllers(); // DBコンテキストの登録。(テーブルがなければ作成する。) services.AddDbContext <DatabaseContext>(options => options.UseSqlServer( Configuration.GetValue <string>("dbConnectionString"))); //services.AddDbContext<DatabaseContext>(options => options.UseInMemoryDatabase(databaseName: "sample")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Application Insightsへのログ出力設定 // // NOTE: https://docs.microsoft.com/ja-jp/azure/azure-monitor/app/asp-net-core#configuration-recommendation-for-microsoftapplicationinsightsaspnetcore-sdk-2150--above // /* * services.AddSingleton(typeof(ITelemetryChannel), new ServerTelemetryChannel() { StorageFolder = "./" }); * var telemetryConfigutaion = new TelemetryClientConfigure(Configuration.GetValue<string>("ApplicationInsights_InstrumentationKey")).aiOptions; * services.AddApplicationInsightsTelemetry(telemetryConfigutaion); * services.AddLogging(loggingBuilder => * { * loggingBuilder.ClearProviders(); * loggingBuilder.AddApplicationInsights(Configuration.GetValue<string>("ApplicationInsights_InstrumentationKey")); * loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider> * ("", LogLevel.Error); * loggingBuilder.AddConsole(); * }); */ string appInsightsKey = Configuration.GetValue <string>("ApplicationInsights_InstrumentationKey"); string logLevel = Configuration.GetValue <string>("Log_Level"); services = TelemetryClientConfigure.ConfigureServerTelemetryChannel(services, appInsightsKey); services = myILoggerProvider.Congfigure(services, appInsightsKey, logLevel); services.AddControllers() .AddNewtonsoftJson(); }
public override void Configure(IFunctionsHostBuilder builder) { builder.Services.AddWebJobs(x => { return; }).AddKafka( (KafkaOptions options) => { options.MaxBatchSize = builder.GetContext().Configuration.GetValue <int>("KafkaExtension_MaxBatchSize"); options.SubscriberIntervalInSeconds = builder.GetContext().Configuration.GetValue <int>("KafkaExtension_SubscriberIntervalInSeconds"); options.ExecutorChannelCapacity = builder.GetContext().Configuration.GetValue <int>("KafkaExtension_ExecutorChannelCapacity"); options.ChannelFullRetryIntervalInMs = builder.GetContext().Configuration.GetValue <int>("KafkaExtension_ChannelFullRetryIntervalInMs"); if (!String.IsNullOrEmpty(builder.GetContext().Configuration.GetValue <string>("Librd_LibkafkaDebug"))) { options.LibkafkaDebug = builder.GetContext().Configuration.GetValue <string>("Librd_LibkafkaDebug"); } }); string appInsightsKey = builder.GetContext().Configuration.GetValue <string>("ApplicationInsights_InstrumentationKey"); string logLevel = builder.GetContext().Configuration.GetValue <string>("Log_Level"); // IFunctionsConfigurationBuilderを別クラスのメソッドで初期化する。 // ServerTelemetryChannelにするとログがでない。 //builder = TelemetryClientConfigure.ConfigureFunctionsServerTelemetryChannel(builder, appInsightsKey); builder = TelemetryClientConfigure.ConfigureFunctionsInMemoryTelemetryChannel(builder, appInsightsKey); builder = myILoggerProvider.Congfigure(builder, appInsightsKey, logLevel); //builder.Services.AddApplicationInsightsTelemetry(aiOptions); builder.Services.AddSingleton <Functions>(); //worker service向け //builder.Services.AddApplicationInsightsTelemetryWorkerService(telemetryConfigutaion); builder.Services.BuildServiceProvider(true); }
public override void Configure(IFunctionsHostBuilder builder) { IWebJobsBuilder hBuilder = builder.Services.AddWebJobs(x => { return; }); hBuilder.AddKafka(); string appInsightsKey = builder.GetContext().Configuration.GetValue <string>("ApplicationInsights_InstrumentationKey"); string logLevel = builder.GetContext().Configuration.GetValue <string>("Log_Level"); /* ILoggerの利用。Functionsでは成功していない。 * builder.Services.AddLogging(loggingBuilder => * { * //loggingBuilder.ClearProviders(); * loggingBuilder.AddApplicationInsights(appInsightsKey); * loggingBuilder.AddConsole(); * loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("Category", LogLevel.Information); * }).BuildServiceProvider(); */ /* * Server TelemetryChannelで実装 * builder.Services.AddSingleton(typeof(ITelemetryChannel), * new ServerTelemetryChannel() { StorageFolder = "./" }); */ // InMemoryChannelで実装 builder.Services.AddSingleton(typeof(ITelemetryChannel), new InMemoryChannel() { MaxTelemetryBufferCapacity = 19898 }); var aiOptions = TelemetryClientConfigure.ConfigureServiceOptions(appInsightsKey); /* IFunctionsConfigurationBuilderを別クラスのメソッドで初期化する。 * //builder = TelemetryClientConfigure.ConfigureFunctionsInMemoryTelemetryChannel(builder, appInsightsKey); * //builder = myILoggerProvider.Congfigure(builder, appInsightsKey, logLevel); */ builder.Services.AddApplicationInsightsTelemetry(aiOptions); builder.Services.AddSingleton <Functions>(); //builder.Services.AddApplicationInsightsTelemetryWorkerService(telemetryConfigutaion); builder.Services.BuildServiceProvider(true); }