public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { // Default registration. loggerFactory.AddProvider(new ColoredConsoleLoggerProvider( new ColoredConsoleLoggerConfiguration { LogLevel = LogLevel.Error, Color = ConsoleColor.Red })); // Custom registration with default values. loggerFactory.AddColoredConsoleLogger(); // Custom registration with a new configuration instance. loggerFactory.AddColoredConsoleLogger(new ColoredConsoleLoggerConfiguration { LogLevel = LogLevel.Debug, Color = ConsoleColor.Gray }); // Custom registration with a configuration object. loggerFactory.AddColoredConsoleLogger(c => { c.LogLevel = LogLevel.Information; c.Color = ConsoleColor.Blue; }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
public static ILoggerFactory AddColoredConsoleLogger(this ILoggerFactory loggerFactory, Action <DbLoggerConfiguration> configure) { var config = new DbLoggerConfiguration(); configure(config); return(loggerFactory.AddColoredConsoleLogger(config)); }
public static ILoggerFactory AddColoredConsoleLogger( this ILoggerFactory loggerFactory) { var config = new ColoredConsoleLoggerConfiguration(); return(loggerFactory.AddColoredConsoleLogger(config)); }
// 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) { loggerFactory.AddColoredConsoleLogger(); loggerFactory.AddColoredConsoleLogger(new ColoredConsoleLoggerConfiguration { LogLevel = LogLevel.Debug, Color = ConsoleColor.Gray }); loggerFactory.AddColoredConsoleLogger(c => { c.LogLevel = LogLevel.Information; c.Color = ConsoleColor.Blue; }); //start logging to the console var logger = loggerFactory.CreateLogger <ConsoleLogger>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseAuthentication(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseMvc(routes => { routes.MapRoute("default", "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); }
public async Task InvokeAsync( HttpContext httpContext, ApplicationDbContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, RoleManager <IdentityRole> roleManager, ILoggerFactory loggerFactory) { bool hasAdminRole = await roleManager.RoleExistsAsync("Admin"); if (!hasAdminRole) { var role = new IdentityRole { Name = "Admin" }; await roleManager.CreateAsync(role); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", FirstName = "Ad", LastName = "Ministrator", SecurityStamp = Guid.NewGuid().ToString() //UniqueCitizenNumber = Guid.NewGuid().ToString() }; await userManager.CreateAsync(user, "Administ0912"); await userManager.AddToRoleAsync(user, "Admin"); } bool hasUserRole = await roleManager.RoleExistsAsync("User"); if (!hasUserRole) { var role = new IdentityRole { Name = "User" }; await roleManager.CreateAsync(role); } loggerFactory.AddColoredConsoleLogger(c => { c.LogLevel = LogLevel.Information; c.Color = ConsoleColor.Yellow; c.Message = "Roles and admin user were added to the database."; }); await this.next(httpContext); }
// 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) { /***** you can comment his to avoid any replication of logs********/ //loggerFactory.AddAzureWebAppDiagnostics(); //loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddDebug(); loggerFactory.AddColoredConsoleLogger(c => { c.LogLevel = LogLevel.Information; c.Color = ConsoleColor.White; }); /* You can use the extension method also to configure logging * * loggerFactory.AddColoredConsoleLogger(c=> * { * c.LogLevel = LogLevel.Information; * c.Color = ConsoleColor.White; * }); * */ if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// 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) { loggerFactory.AddColoredConsoleLogger(); //loggerFactory.AddColoredConsoleLogger(c => //{ // c.LogLevel = LogLevel.Information; // c.Color = ConsoleColor.Blue; //}); //loggerFactory.AddColoredConsoleLogger(c => //{ // c.LogLevel = LogLevel.Debug; // c.Color = ConsoleColor.Gray; //}); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); // Register the Swagger generator and the Swagger UI middlewares app.UseOpenApi(); app.UseSwaggerUi3(); app.UseHttpsRedirection(); app.UseRouting(); // global cors policy app.UseCors("AuthCorsPolicy"); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }