1 Star 1 Fork 8

yupeiyong/VueJS ASP.NET Core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 2.56 KB
一键复制 编辑 原始数据 按行查看 历史
电脑程序爱好者 提交于 2020-01-07 22:53 +08:00 . init created
using System;
using Vue_AspNetCore_Project.Data;
using Vue_AspNetCore_Project.Models;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
namespace Vue_AspNetCore_Project
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File(@"Logs/log.txt",
fileSizeLimitBytes: 1_000_000,
rollOnFileSizeLimit: true,
shared: true,
flushToDiskInterval: TimeSpan.FromSeconds(1))
.CreateLogger();
try
{
Log.Information("Starting web host");
var host = CreateWebHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var dbContext = services.GetRequiredService<ApplicationDbContext>();
DbContextExtensions.UserManager = services.GetService<UserManager<ApplicationUser>>();
DbContextExtensions.RoleManager = services.GetService<RoleManager<ApplicationRole>>();
dbContext.Database.Migrate();
dbContext.EnsureSeeded().Wait();
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred while seeding the database.");
}
}
host.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog()
.UseUrls("http://localhost:6001"); //直接指定端口;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/yupeiyong/VueJS_AspNetCore.git
git@gitee.com:yupeiyong/VueJS_AspNetCore.git
yupeiyong
VueJS_AspNetCore
VueJS ASP.NET Core
master

搜索帮助