Skip to content

Commit

Permalink
Merge pull request #193 from serilog/supply-service-provider
Browse files Browse the repository at this point in the history
Update to show new UseSerilog() overload including service provider
  • Loading branch information
nblumhardt authored May 13, 2020
2 parents 5386292 + 8151912 commit 7da9569
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ app.UseSerilogRequestLogging(options =>
You can alternatively configure Serilog inline, in `BuildWebHost()`, using a delegate as shown below:

```csharp
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console())
```

This has the advantage of making the `hostingContext`'s `Configuration` object available for [configuration of the logger](https://github.com/serilog/serilog-settings-configuration), but at the expense of losing `Exception`s raised earlier in program startup.
This has the advantage of making a service provider and the `hostingContext`'s `Configuration` object available for [configuration of the logger](https://github.com/serilog/serilog-settings-configuration), but at the expense of losing `Exception`s raised earlier in program startup.

If this method is used, `Log.Logger` is assigned implicitly, and closed when the app is shut down.

Expand Down
6 changes: 3 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"allowPrerelease": false,
"version": "3.1.100",
"rollForward": "latestPatch"
"version": "3.1.201",
"rollForward": "latestFeature"
}
}
}
7 changes: 2 additions & 5 deletions samples/InlineInitializationSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ public static void Main(string[] args)

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.WriteTo.Debug()
Expand Down
2 changes: 0 additions & 2 deletions samples/InlineInitializationSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Net;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace InlineInitializationSample
{
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.AspNetCore/Serilog.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Serilog support for ASP.NET Core logging</Description>
<VersionPrefix>3.3.0</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<Authors>Microsoft;Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -27,7 +27,7 @@

<ItemGroup>
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.1.0-dev-*" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
Expand Down

0 comments on commit 7da9569

Please sign in to comment.