-
Notifications
You must be signed in to change notification settings - Fork 16
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 #4 from damienbod/dev-updates
Improve startup of projects
- Loading branch information
Showing
25 changed files
with
476 additions
and
548 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,34 @@ | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
using WebApi; | ||
|
||
namespace WebApi; | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
public class Program | ||
Log.Information("Starting up MultiAADWebApi"); | ||
|
||
try | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Host.UseSerilog((ctx, lc) => lc | ||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") | ||
.WriteTo.File("../_logs-MultiAADWebApi.txt") | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
.ReadFrom.Configuration(ctx.Configuration)); | ||
|
||
try | ||
{ | ||
Log.Information("Starting web host"); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
var app = builder | ||
.ConfigureServices() | ||
.ConfigurePipeline(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration | ||
.ReadFrom.Configuration(hostingContext.Configuration) | ||
.Enrich.FromLogContext() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.File("../_logs-MultiAADWebApi.txt") | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
app.Run(); | ||
} | ||
catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" && ex.GetType().Name is not "HostAbortedException") | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
} | ||
finally | ||
{ | ||
Log.Information("Shut down complete"); | ||
Log.CloseAndFlush(); | ||
} |
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,48 +1,34 @@ | ||
using RazorAzureAD; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace RazorAzureAD; | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
public class Program | ||
Log.Information("Starting up RazorAzureAD"); | ||
|
||
try | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Host.UseSerilog((ctx, lc) => lc | ||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") | ||
.WriteTo.File("../_logs-TestMultiApis.txt") | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
.ReadFrom.Configuration(ctx.Configuration)); | ||
|
||
try | ||
{ | ||
Log.Information("Starting web host"); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
var app = builder | ||
.ConfigureServices() | ||
.ConfigurePipeline(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration | ||
.ReadFrom.Configuration(hostingContext.Configuration) | ||
.Enrich.FromLogContext() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.File("../_logs-TestMultiApis.txt") | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
app.Run(); | ||
} | ||
catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" && ex.GetType().Name is not "HostAbortedException") | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
} | ||
finally | ||
{ | ||
Log.Information("Shut down complete"); | ||
Log.CloseAndFlush(); | ||
} |
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
Oops, something went wrong.