-
Notifications
You must be signed in to change notification settings - Fork 209
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 #378 from serilog/dev
8.0.2 Release
- Loading branch information
Showing
11 changed files
with
103 additions
and
153 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,47 +1,69 @@ | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Templates; | ||
using Serilog.Templates.Themes; | ||
|
||
namespace Sample; | ||
// The initial "bootstrap" logger is able to log errors during start-up. It's completely replaced by the | ||
// logger configured in `AddSerilog()` below, once configuration and dependency-injection have both been | ||
// set up successfully. | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
public static class Program | ||
Log.Information("Starting up!"); | ||
|
||
try | ||
{ | ||
public static int Main(string[] args) | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddSerilog((services, lc) => lc | ||
.ReadFrom.Configuration(builder.Configuration) | ||
.ReadFrom.Services(services) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(new ExpressionTemplate( | ||
// Include trace and span ids when present. | ||
"[{@t:HH:mm:ss} {@l:u3}{#if @tr is not null} ({substring(@tr,0,4)}:{substring(@sp,0,4)}){#end}] {@m}\n{@x}", | ||
theme: TemplateTheme.Code))); | ||
|
||
builder.Services.AddControllersWithViews(); | ||
|
||
await using var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
// The initial "bootstrap" logger is able to log errors during start-up. It's completely replaced by the | ||
// logger configured in `UseSerilog()` below, once configuration and dependency-injection have both been | ||
// set up successfully. | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
Log.Information("Starting up!"); | ||
|
||
try | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
|
||
Log.Information("Stopped cleanly"); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "An unhandled exception occurred during bootstrapping"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
app.UseExceptionHandler("/Home/Error"); | ||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. | ||
app.UseHsts(); | ||
} | ||
|
||
// Write streamlined request completion events, instead of the more verbose ones from the framework. | ||
// To use the default framework request logging instead, remove this line and set the "Microsoft" | ||
// level in appsettings.json to "Information". | ||
app.UseSerilogRequestLogging(); | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Home}/{action=Index}/{id?}"); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSerilog((context, services, configuration) => configuration | ||
.ReadFrom.Configuration(context.Configuration) | ||
.ReadFrom.Services(services) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console(new ExpressionTemplate( | ||
// Include trace and span ids when present. | ||
"[{@t:HH:mm:ss} {@l:u3}{#if @tr is not null} ({substring(@tr,0,4)}:{substring(@sp,0,4)}){#end}] {@m}\n{@x}"))) | ||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()); | ||
await app.RunAsync(); | ||
|
||
Log.Information("Stopped cleanly"); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "An unhandled exception occurred during bootstrapping"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
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 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
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
Oops, something went wrong.