-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from nblumhardt/readme-updates
Update samples and README to use recent .NET host APIs
- Loading branch information
Showing
5 changed files
with
98 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Hosting; | ||
using Serilog; | ||
|
||
namespace WebApplicationSample; | ||
|
||
public static class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
Log.Information("Starting up!"); | ||
Log.Information("Starting up!"); | ||
|
||
try | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
|
||
try | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
builder.Services.AddSerilog((services, loggerConfiguration) => loggerConfiguration | ||
.WriteTo.Console() | ||
.ReadFrom.Configuration(builder.Configuration) | ||
.ReadFrom.Services(services)); | ||
|
||
Log.Information("Stopped cleanly"); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "An unhandled exception occured during bootstrapping"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
var app = builder.Build(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSerilog((context, services, configuration) => configuration | ||
.WriteTo.Console() | ||
.ReadFrom.Configuration(context.Configuration) | ||
.ReadFrom.Services(services)) | ||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); | ||
} | ||
app.MapGet("/", () => | ||
{ | ||
Log.Information("Saying hello"); | ||
return "Hello World!"; | ||
}); | ||
|
||
await app.RunAsync(); | ||
|
||
Log.Information("Stopped cleanly"); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "An unhandled exception occured during bootstrapping"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
await Log.CloseAndFlushAsync(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters