Skip to content

Commit d0b616b

Browse files
authored
Merge pull request #287 from serilog/dev
5.0.0 Release
2 parents 5b02055 + d9e072e commit d0b616b

12 files changed

+45
-85
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
contact_links:
2+
- name: Ask for help
3+
url: https://github.com/serilog/serilog/wiki/Usage-help
4+
about: Ask the community for help on how to use Serilog

.github/ISSUE_TEMPLATE/usage-help.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,6 @@ __pycache__/
286286
*.btm.cs
287287
*.odx.cs
288288
*.xsd.cs
289+
290+
samples/Sample/logs/
291+

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dotnet add package Serilog.AspNetCore
1818

1919
```csharp
2020
using Serilog;
21+
using Serilog.Events;
2122

2223
public class Program
2324
{
@@ -197,10 +198,11 @@ The downside of initializing Serilog first is that services from the ASP.NET Cor
197198

198199
To address this, Serilog supports two-stage initialization. An initial "bootstrap" logger is configured immediately when the program starts, and this is replaced by the fully-configured logger once the host has loaded.
199200

200-
To use this technique, first replace the initial `CreateLogger()` call with `CreateBoostrapLogger()`:
201+
To use this technique, first replace the initial `CreateLogger()` call with `CreateBootstrapLogger()`:
201202

202203
```csharp
203204
using Serilog;
205+
using Serilog.Events;
204206

205207
public class Program
206208
{

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ deploy:
1212
- provider: NuGet
1313
skip_symbols: true
1414
api_key:
15-
secure: jZtLAmD4ALF9x1BZR1DiV3KhKlliWbzRUAw73xfMZaBsvz19123qLz2zw1+hPdcn
15+
secure: U7I8Skf+EcC7PiqvLWpSzPqNhCg03cqDOi4OtAkb+ZelMlQj1YoKDX8r1pdQzy7H
1616
on:
1717
branch: /^(main|dev)$/
1818
- provider: GitHub

samples/Sample/logs/log-20210214.txt

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RequestLoggingMiddleware
3333
readonly Action<IDiagnosticContext, HttpContext> _enrichDiagnosticContext;
3434
readonly Func<HttpContext, double, Exception, LogEventLevel> _getLevel;
3535
readonly ILogger _logger;
36+
readonly bool _includeQueryInRequestPath;
3637
static readonly LogEventProperty[] NoProperties = new LogEventProperty[0];
3738

3839
public RequestLoggingMiddleware(RequestDelegate next, DiagnosticContext diagnosticContext, RequestLoggingOptions options)
@@ -45,6 +46,7 @@ public RequestLoggingMiddleware(RequestDelegate next, DiagnosticContext diagnost
4546
_enrichDiagnosticContext = options.EnrichDiagnosticContext;
4647
_messageTemplate = new MessageTemplateParser().Parse(options.MessageTemplate);
4748
_logger = options.Logger?.ForContext<RequestLoggingMiddleware>();
49+
_includeQueryInRequestPath = options.IncludeQueryInRequestPath;
4850
}
4951

5052
// ReSharper disable once UnusedMember.Global
@@ -91,7 +93,7 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector
9193
var properties = collectedProperties.Concat(new[]
9294
{
9395
new LogEventProperty("RequestMethod", new ScalarValue(httpContext.Request.Method)),
94-
new LogEventProperty("RequestPath", new ScalarValue(GetPath(httpContext))),
96+
new LogEventProperty("RequestPath", new ScalarValue(GetPath(httpContext, _includeQueryInRequestPath))),
9597
new LogEventProperty("StatusCode", new ScalarValue(statusCode)),
9698
new LogEventProperty("Elapsed", new ScalarValue(elapsedMs))
9799
});
@@ -107,14 +109,16 @@ static double GetElapsedMilliseconds(long start, long stop)
107109
return (stop - start) * 1000 / (double)Stopwatch.Frequency;
108110
}
109111

110-
static string GetPath(HttpContext httpContext)
112+
static string GetPath(HttpContext httpContext, bool includeQueryInRequestPath)
111113
{
112114
/*
113115
In some cases, like when running integration tests with WebApplicationFactory<T>
114-
the RawTarget returns an empty string instead of null, in that case we can't use
116+
the Path returns an empty string instead of null, in that case we can't use
115117
?? as fallback.
116118
*/
117-
var requestPath = httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget;
119+
var requestPath = includeQueryInRequestPath
120+
? httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget
121+
: httpContext.Features.Get<IHttpRequestFeature>()?.Path;
118122
if (string.IsNullOrEmpty(requestPath))
119123
{
120124
requestPath = httpContext.Request.Path.ToString();

src/Serilog.AspNetCore/AspNetCore/RequestLoggingOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ static LogEventLevel DefaultGetLevel(HttpContext ctx, double _, Exception ex) =>
6868
/// </summary>
6969
public ILogger Logger { get; set; }
7070

71+
/// <summary>
72+
/// Include the full URL query string in the <c>RequestPath</c> property
73+
/// that is attached to request log events. The default is <c>false</c>.
74+
/// </summary>
75+
public bool IncludeQueryInRequestPath { get; set; }
76+
7177
/// <summary>
7278
/// Constructor
7379
/// </summary>

src/Serilog.AspNetCore/Serilog.AspNetCore.csproj

Lines changed: 9 additions & 5 deletions
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>4.1.0</VersionPrefix>
5+
<VersionPrefix>5.0.0</VersionPrefix>
66
<Authors>Microsoft;Serilog Contributors</Authors>
77
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -24,13 +24,17 @@
2424
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
2525
</ItemGroup>
2626

27+
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netstandard2.1'">
28+
<DefineConstants>$(DefineConstants);HOSTBUILDER</DefineConstants>
29+
</PropertyGroup>
30+
2731
<ItemGroup>
2832
<PackageReference Include="Serilog" Version="2.10.0" />
29-
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.2" />
30-
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
31-
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
33+
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />
34+
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
35+
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
3236
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
33-
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
37+
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
3438
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
3539
</ItemGroup>
3640

src/Serilog.AspNetCore/SerilogWebHostBuilderExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public static class SerilogWebHostBuilderExtensions
3838
/// <c>WriteTo.Providers()</c> configuration method, enabling other <see cref="ILoggerProvider"/>s to receive events. By
3939
/// default, only Serilog sinks will receive events.</param>
4040
/// <returns>The web host builder.</returns>
41+
#if HOSTBUILDER
42+
[Obsolete("Prefer UseSerilog() on IHostBuilder")]
43+
#endif
4144
public static IWebHostBuilder UseSerilog(
4245
this IWebHostBuilder builder,
4346
ILogger logger = null,
@@ -83,6 +86,9 @@ public static IWebHostBuilder UseSerilog(
8386
/// the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers. Specify
8487
/// <c>true</c> to write events to all providers.</param>
8588
/// <returns>The web host builder.</returns>
89+
#if HOSTBUILDER
90+
[Obsolete("Prefer UseSerilog() on IHostBuilder")]
91+
#endif
8692
public static IWebHostBuilder UseSerilog(
8793
this IWebHostBuilder builder,
8894
Action<WebHostBuilderContext, LoggerConfiguration> configureLogger,

test/Serilog.AspNetCore.Tests/Serilog.AspNetCore.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" PrivateAssets="All" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
1919
<PackageReference Include="xunit" Version="2.4.1" />
2020
</ItemGroup>
2121

test/Serilog.AspNetCore.Tests/SerilogWebHostBuilderExtensionsTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
using Serilog.Filters;
1313
using Serilog.AspNetCore.Tests.Support;
1414

15+
// Newer frameworks provide IHostBuilder
16+
#pragma warning disable CS0618
17+
1518
namespace Serilog.AspNetCore.Tests
1619
{
1720
public class SerilogWebHostBuilderExtensionsTests : IClassFixture<SerilogWebApplicationFactory>

0 commit comments

Comments
 (0)