Exemplo n.º 1
0
        // 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"));
        }
Exemplo n.º 2
0
        // 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();
        }