Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            var config = Configuration.GetAWSLoggingConfigSection();

            loggerFactory.AddAWSProvider(config);


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/Prod/swagger/v1/swagger.json", "WebAPIChallenge v1");
            });
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAdvert.SearchApi v1"));
            }

            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection(), formatter: (logLevel, loggerMessage, exception) => {
                return($"[{DateTime.Now} {logLevel} {loggerMessage} {exception?.Message} {exception?.StackTrace}");
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseHealthChecks("/Health");
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error/Error");
                app.UseStatusCodePagesWithReExecute("/Error/Errors/{0}");
                app.UseHsts();

                loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");
            });
        }
Ejemplo n.º 5
0
        private void ConfigureLogger(ILoggerFactory loggerFactory, AmazonConfiguration amazonConfiguration)
        {
            var loggerConfig = Configuration.GetAWSLoggingConfigSection();

            loggerConfig.Config.Credentials = amazonConfiguration.Credentials;

            loggerFactory.AddAWSProvider(loggerConfig, formatter: (logLevel, message, exception) => $"[{DateTime.UtcNow}] {logLevel}: {message}");
        }
Ejemplo n.º 6
0
        public LambdaLogger(ILoggerFactory loggerFactory)
        {
            // Create a logging provider based on the configuration information passed through the appsettings.json
            // You can even provide your custom formatting.
            loggerFactory.AddAWSProvider(this.Configuration.GetAWSLoggingConfigSection("AWS.Logging"),
                                         formatter: (logLevel, message, exception) => $"[{DateTime.UtcNow}] {logLevel}: {message}");

            // Create a logger instance from the loggerFactory
            MachineLogger = loggerFactory.CreateLogger("a");
            MachineLogger.LogInformation("Check the AWS Console CloudWatch Logs");
        }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

        //ILoggerFactory added into method parameters, after aws.logger.aspnetcore nuget package.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //we say that we are going to use aws log provider and get its configuration fromde appsettings.json. then use the log format as below:
            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection(),
                                         formatter: (loglevel, message, exception) => $"[{DateTime.Now} {loglevel} {message} {exception?.Message} {exception?.StackTrace}]");

            app.UseHealthChecks("/health");
            app.UseMvc();
        }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // Enable logging to CloudWatch
            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());

            // Write to the logs
            var logger = loggerFactory.CreateLogger <Startup>();

            logger.LogInformation("CloudWatch logging enabled.");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMvc();
        }
Ejemplo n.º 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var recipeshelfConfiguration = Configuration.GetSection("RecipeShelf");

            if (recipeshelfConfiguration.GetValue <bool>("LogToConsole"))
            {
                loggerFactory.AddConsole(Configuration.GetSection("Logging"));
                loggerFactory.AddDebug();
            }
            else
            {
                loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());
            }

            app.UseMvc();
        }
Ejemplo n.º 10
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDeveloperExceptionPage();
            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());

            app.UseMvc();
            app.Run(async context =>
            {
                await context.Response.WriteAsync("Calculator is online - Version 1.1");
            });
        }
Ejemplo n.º 11
0
        private void Configure(ILoggerFactory factory, LogLevel currentLevel)
        {
#if DEBUG
            bool logDirect = true;
#else
            bool logDirect    = false;
            var  logDirectStr = Environment.GetEnvironmentVariable("LOGGING_CLOUDWATCH");
            if (!string.IsNullOrEmpty(logDirectStr) && int.TryParse(logDirectStr, out var logDirectVal) && logDirectVal > 0)
            {
                logDirect = true;
            }
#endif
            if (logDirect)
            {
                var config = new AWSLoggerConfig()
                {
                    LibraryLogFileName = Path.Combine(Path.GetTempPath(), "aws-logger-errors.txt")
                };

                var group = Environment.GetEnvironmentVariable("LOGGING_CLOUDWATCH_GROUP");
#if DEBUG
                config.LogGroup = "SuperNova/default/debug";
#else
                config.LogGroup = string.IsNullOrEmpty(group) ? "SuperNova/default" : group;
#endif

                var batchPushSecsStr = Environment.GetEnvironmentVariable("LOGGING_CLOUDWATCH_BATCHPUSHSECS");
                if (!string.IsNullOrEmpty(batchPushSecsStr) && int.TryParse(batchPushSecsStr, out var batchPushSecs) && batchPushSecs > 0)
                {
                    config.BatchPushInterval = new TimeSpan(0, 0, batchPushSecs);
                }

                var batchPushBytesStr = Environment.GetEnvironmentVariable("LOGGING_CLOUDWATCH_BATCHPUSHBYTES");
                if (!string.IsNullOrEmpty(batchPushBytesStr) && int.TryParse(batchPushBytesStr, out var batchPushBytes) && batchPushBytes > 0)
                {
                    config.BatchSizeInBytes = batchPushBytes;
                }
                _factory.AddAWSProvider(config, currentLevel);
            }
            else
            {
                _factory.AddLambdaLogger(new LambdaLoggerOptions
                {
                    Filter = (s, logLevel) => logLevel >= currentLevel
                });
            }
        }
Ejemplo n.º 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseFileServer();
            app.UseForwardedHeaders();
            app.UseDeveloperExceptionPage();

            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());

            app.UseMiddleware <CloudWatchExecutionTimeService>();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "CoinBot API V1");
            });

            app.UseMvc();

            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());
        }
Ejemplo n.º 14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            var config = Configuration.GetAWSLoggingConfigSection();

            // Create a logging provider based on the configuration information passed through the appsettings.json
            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection());

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Ejemplo n.º 15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            loggerFactory.AddAWSProvider(Configuration.GetAWSLoggingConfigSection(),
                                         (logLevel, message, exception) => $"[{DateTime.Now} {logLevel} {message} {exception?.Message}]"
                                         );
            app.UseHttpsRedirection();
            app.UseMvc();
            app.UseHealthChecks("/health");
        }
Ejemplo n.º 16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            var loggerConfig = this.Configuration.GetAWSLoggingConfigSection();

            loggerConfig.Config.Profile = Configuration.GetAWSOptions().Profile;
            loggerFactory.AddAWSProvider(loggerConfig);

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseMiddleware(typeof(ErrorHandlerMiddleware));

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        /// <summary>
        /// Configures default aws logging for the alexa skill.
        /// </summary>
        /// <param name="serviceProvider">The DI service provider.</param>
        protected void ConfigureLogging(IServiceProvider serviceProvider)
        {
            IEnvironmentService environmentService = serviceProvider.GetService <IEnvironmentService>();
            ILoggerFactory      loggerFactory      = serviceProvider.GetService <ILoggerFactory>();
            IConfiguration      configuration      = ConfigurationService.GetConfiguration();

            // Add Console and Debug logging in development/unittest.
            if (environmentService.IsUnitTest || environmentService.IsDevelopment)
            {
                loggerFactory.AddConsole(configuration.GetSection("Logging"));
                loggerFactory.AddDebug();
            }

            // Add AWS logging, optional.
            AlexaLambdaConfiguration alexaLambdaConfiguration = serviceProvider.GetService <AlexaLambdaConfiguration>();

            if (alexaLambdaConfiguration.EnableAlexaLogger)
            {
                loggerFactory.AddAWSProvider(configuration.GetAWSLoggingConfigSection());
            }
        }