Skip to content

Commit 5fb585d

Browse files
authored
Merge pull request #40 from serilog/dev
2.1.1 Release
2 parents 6e59a36 + b883014 commit 5fb585d

File tree

5 files changed

+49
-23
lines changed

5 files changed

+49
-23
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Program
4444
}
4545
```
4646

47-
Then, add `UseSerilog()` to the web host builder in `BuildWebHost()`.
47+
**Then**, add `UseSerilog()` to the web host builder in `BuildWebHost()`.
4848

4949
```csharp
5050
public static IWebHost BuildWebHost(string[] args) =>
@@ -92,6 +92,7 @@ With _Serilog.AspNetCore_ installed and configured, you can write log messages d
9292
You can alternatively configure Serilog using a delegate as shown below:
9393

9494
```csharp
95+
// dotnet add package Serilog.Settings.Configuration
9596
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
9697
.ReadFrom.Configuration(hostingContext.Configuration)
9798
.Enrich.FromLogContext()

samples/SimpleWebSample/Program.cs

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System;
1+
using System;
22
using System.IO;
3+
using Microsoft.AspNetCore;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.Extensions.Configuration;
56
using Serilog;
@@ -8,16 +9,18 @@ namespace SimpleWebSample
89
{
910
public class Program
1011
{
12+
public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
13+
.SetBasePath(Directory.GetCurrentDirectory())
14+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
15+
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
16+
.AddEnvironmentVariables()
17+
.Build();
18+
1119
public static int Main(string[] args)
1220
{
13-
var configuration = new ConfigurationBuilder()
14-
.SetBasePath(Directory.GetCurrentDirectory())
15-
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
16-
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
17-
.Build();
1821

1922
Log.Logger = new LoggerConfiguration()
20-
.ReadFrom.Configuration(configuration)
23+
.ReadFrom.Configuration(Configuration)
2124
.Enrich.FromLogContext()
2225
.WriteTo.Console()
2326
.CreateLogger();
@@ -26,16 +29,7 @@ public static int Main(string[] args)
2629
{
2730
Log.Information("Getting the motors running...");
2831

29-
var host = new WebHostBuilder()
30-
.UseKestrel()
31-
.UseContentRoot(Directory.GetCurrentDirectory())
32-
.UseIISIntegration()
33-
.UseStartup<Startup>()
34-
.UseConfiguration(configuration)
35-
.UseSerilog()
36-
.Build();
37-
38-
host.Run();
32+
BuildWebHost(args).Run();
3933

4034
return 0;
4135
}
@@ -49,5 +43,12 @@ public static int Main(string[] args)
4943
Log.CloseAndFlush();
5044
}
5145
}
46+
47+
public static IWebHost BuildWebHost(string[] args) =>
48+
WebHost.CreateDefaultBuilder(args)
49+
.UseStartup<Startup>()
50+
.UseConfiguration(Configuration)
51+
.UseSerilog()
52+
.Build();
5253
}
5354
}

samples/SimpleWebSample/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"MinimumLevel": {
44
"Default": "Debug",
55
"Override": {
6-
"Microsoft": "Warning",
6+
"Microsoft": "Information",
77
"System": "Warning"
88
}
99
}

src/Serilog.AspNetCore/AspNetCore/SerilogLoggerFactory.cs

+27-3
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,49 @@
1818

1919
namespace Serilog.AspNetCore
2020
{
21-
class SerilogLoggerFactory : ILoggerFactory
21+
/// <summary>
22+
/// Implements <see cref="ILoggerFactory"/> so that we can inject Serilog Logger.
23+
/// </summary>
24+
public class SerilogLoggerFactory : ILoggerFactory
2225
{
23-
readonly SerilogLoggerProvider _provider;
26+
private readonly SerilogLoggerProvider _provider;
2427

25-
public SerilogLoggerFactory(Serilog.ILogger logger = null, bool dispose = false)
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="SerilogLoggerFactory"/> class.
30+
/// </summary>
31+
/// <param name="logger">The Serilog logger; if not supplied, the static <see cref="Serilog.Log"/> will be used.</param>
32+
/// <param name="dispose">When true, dispose <paramref name="logger"/> when the framework disposes the provider. If the
33+
/// logger is not specified but <paramref name="dispose"/> is true, the <see cref="Log.CloseAndFlush()"/> method will be
34+
/// called on the static <see cref="Log"/> class instead.</param>
35+
public SerilogLoggerFactory(ILogger logger = null, bool dispose = false)
2636
{
2737
_provider = new SerilogLoggerProvider(logger, dispose);
2838
}
2939

40+
/// <summary>
41+
/// Disposes the provider.
42+
/// </summary>
3043
public void Dispose()
3144
{
3245
_provider.Dispose();
3346
}
3447

48+
/// <summary>
49+
/// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
50+
/// </summary>
51+
/// <param name="categoryName">The category name for messages produced by the logger.</param>
52+
/// <returns>
53+
/// The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.
54+
/// </returns>
3555
public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
3656
{
3757
return _provider.CreateLogger(categoryName);
3858
}
3959

60+
/// <summary>
61+
/// Adds an <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" /> to the logging system.
62+
/// </summary>
63+
/// <param name="provider">The <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
4064
public void AddProvider(ILoggerProvider provider)
4165
{
4266
SelfLog.WriteLine("Ignoring added logger provider {0}", provider);

src/Serilog.AspNetCore/Serilog.AspNetCore.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Serilog support for ASP.NET Core logging</Description>
5-
<VersionPrefix>2.1.0</VersionPrefix>
5+
<VersionPrefix>2.1.1</VersionPrefix>
66
<Authors>Microsoft;Serilog Contributors</Authors>
77
<TargetFrameworks>netstandard2.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

0 commit comments

Comments
 (0)