Ejemplo n.º 1
0
        public static ILoggerFactory AddCustomLogger(this ILoggerFactory loggerFactory, Action <CustomLoggerConfiguration> configure)
        {
            var config = new CustomLoggerConfiguration();

            configure(config);
            return(loggerFactory.AddCustomLogger(config));
        }
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, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
        {
            Func <ILogsRepository> logRepositoryFactory = () => serviceProvider.GetService <ILogsRepository>();

            loggerFactory.AddCustomLogger(Configuration.GetSection("Logging"), logRepositoryFactory);

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

            app.UseMvc();
        }
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, IHostingEnvironment env, ILoggerFactory loggerFactory, SchoolContext context)
        {
            loggerFactory
            .AddConsole()
            .AddDebug();

            loggerFactory.AddCustomLogger(c =>
            {
                c.LogLevel = LogLevel.Information;
                c.FilePath = $"{System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\\CustomLog.txt";
            });

            DbInitializer.Initialize(context);

            app.UseMvc();
        }
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, IServiceProvider serviceProvider)
        {
            loggerFactory.AddCustomLogger(serviceProvider.GetService <IHttpContextAccessor>());

            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();
            }

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Ejemplo n.º 5
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, IOptions <CustomLoggerSettings> customLoggerSettings, IMailService mailService)
        {
            loggerFactory.AddConsole();

            // Register custom logger
            loggerFactory.AddCustomLogger(customLoggerSettings, mailService, env.IsProduction() ? LogLevel.Error : LogLevel.Information);

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

            app.Run(async(context) =>
            {
                ILogger logger = loggerFactory.CreateLogger <Startup>();

                logger.LogInformation("API LoggerTests 1 - Normal Log");
                logger.LogCritical("API LoggerTests 2 - Critical Log with Send Mail");

                await context.Response.WriteAsync("Test log added, check it out in the `Logs` folder.");
            });
        }