Пример #1
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(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug((category, logLevel) =>
                                   { return(category.StartsWith("Microsoft.EntityFrameworkCore")); });

            NLogProviderOptions options = new NLogProviderOptions();

            loggerFactory.AddNLog(options);
            //loggerFactory.CreateLogger("Microsoft.EntityFrameworkCore");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            SchoolInitializer.Initialize(context);
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (SchoolContext context = new SchoolContext())
            {
                context.Database.EnsureCreated();
                SchoolInitializer.Seed(context);
            }

            using (SchoolContext context = new SchoolContext())
            {
                foreach (var student in context.Students)
                {
                    Console.WriteLine($"{student.FirstName} {student.LastName}");
                }
            }
        }