Closed
Description
Took me half a morning before I figured out what was exactly going on.
My Identity Server project used the provided way here to create the host, but Entity Framework relies on the BuildWebHost
method to analyse it for contexts.
Let me know if you'd like me to change the sample and docs here to below, I believe it contains all that's needed for a valid Serilog + AspNetCore flow.
Program.cs:
public class Program
{
public static IConfiguration Configuration { get; set; }
public static int Main(string[] args)
{
Configuration = CreateConfiguration();
Logging.Config(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development");
try
{
Log.Information("Starting up application");
var host = BuildWebHost(args);
host.Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
private static IConfiguration CreateConfiguration()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(CreateConfiguration())
.UseSerilog()
.UseStartup<Startup>()
.Build();
}
Metadata
Metadata
Assignees
Labels
No labels