Skip to content

Commit

Permalink
Remove Startup.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Dec 22, 2024
1 parent 60c466d commit 3d0dfb0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 61 deletions.
82 changes: 41 additions & 41 deletions sample/CapSample/src/CapSample.HttpApi.Host/Program.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace CapSample
namespace CapSample;

public class Program
{
public class Program
public async static Task<int> Main(string[] args)
{
public static int Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
Log.Logger = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
.MinimumLevel.Information()
#endif
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
#if DEBUG
.WriteTo.Async(c => c.Console())
#endif
.CreateLogger();
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
.WriteTo.Async(c => c.Console())
.CreateLogger();

try
{
Log.Information("Starting CapSample.HttpApi.Host.");
CreateHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly!");
return 1;
}
finally
try
{
Log.Information("Starting web host.");
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
.UseAutofac()
.UseSerilog();
await builder.AddApplicationAsync<CapSampleHttpApiHostModule>();
var app = builder.Build();
await app.InitializeApplicationAsync();
await app.RunAsync();
return 0;
}
catch (Exception ex)
{
if (ex is HostAbortedException)
{
Log.CloseAndFlush();
throw;
}
}

internal static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.AddAppSettingsSecretsJson()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseAutofac()
.UseSerilog();
Log.Fatal(ex, "Host terminated unexpectedly!");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
}
}
20 changes: 0 additions & 20 deletions sample/CapSample/src/CapSample.HttpApi.Host/Startup.cs

This file was deleted.

0 comments on commit 3d0dfb0

Please sign in to comment.