Skip to content

Commit

Permalink
Merge pull request #287 from serilog/dev
Browse files Browse the repository at this point in the history
5.0.0 Release
  • Loading branch information
nblumhardt committed Feb 15, 2022
2 parents 5b02055 + d9e072e commit d0b616b
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 85 deletions.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contact_links:
- name: Ask for help
url: https://github.com/serilog/serilog/wiki/Usage-help
about: Ask the community for help on how to use Serilog
16 changes: 0 additions & 16 deletions .github/ISSUE_TEMPLATE/usage-help.md

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,6 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs

samples/Sample/logs/

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dotnet add package Serilog.AspNetCore

```csharp
using Serilog;
using Serilog.Events;

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

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.

To use this technique, first replace the initial `CreateLogger()` call with `CreateBoostrapLogger()`:
To use this technique, first replace the initial `CreateLogger()` call with `CreateBootstrapLogger()`:

```csharp
using Serilog;
using Serilog.Events;

public class Program
{
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ deploy:
- provider: NuGet
skip_symbols: true
api_key:
secure: jZtLAmD4ALF9x1BZR1DiV3KhKlliWbzRUAw73xfMZaBsvz19123qLz2zw1+hPdcn
secure: U7I8Skf+EcC7PiqvLWpSzPqNhCg03cqDOi4OtAkb+ZelMlQj1YoKDX8r1pdQzy7H
on:
branch: /^(main|dev)$/
- provider: GitHub
Expand Down
56 changes: 0 additions & 56 deletions samples/Sample/logs/log-20210214.txt

This file was deleted.

12 changes: 8 additions & 4 deletions src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RequestLoggingMiddleware
readonly Action<IDiagnosticContext, HttpContext> _enrichDiagnosticContext;
readonly Func<HttpContext, double, Exception, LogEventLevel> _getLevel;
readonly ILogger _logger;
readonly bool _includeQueryInRequestPath;
static readonly LogEventProperty[] NoProperties = new LogEventProperty[0];

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

// ReSharper disable once UnusedMember.Global
Expand Down Expand Up @@ -91,7 +93,7 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector
var properties = collectedProperties.Concat(new[]
{
new LogEventProperty("RequestMethod", new ScalarValue(httpContext.Request.Method)),
new LogEventProperty("RequestPath", new ScalarValue(GetPath(httpContext))),
new LogEventProperty("RequestPath", new ScalarValue(GetPath(httpContext, _includeQueryInRequestPath))),
new LogEventProperty("StatusCode", new ScalarValue(statusCode)),
new LogEventProperty("Elapsed", new ScalarValue(elapsedMs))
});
Expand All @@ -107,14 +109,16 @@ static double GetElapsedMilliseconds(long start, long stop)
return (stop - start) * 1000 / (double)Stopwatch.Frequency;
}

static string GetPath(HttpContext httpContext)
static string GetPath(HttpContext httpContext, bool includeQueryInRequestPath)
{
/*
In some cases, like when running integration tests with WebApplicationFactory<T>
the RawTarget returns an empty string instead of null, in that case we can't use
the Path returns an empty string instead of null, in that case we can't use
?? as fallback.
*/
var requestPath = httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget;
var requestPath = includeQueryInRequestPath
? httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget
: httpContext.Features.Get<IHttpRequestFeature>()?.Path;
if (string.IsNullOrEmpty(requestPath))
{
requestPath = httpContext.Request.Path.ToString();
Expand Down
6 changes: 6 additions & 0 deletions src/Serilog.AspNetCore/AspNetCore/RequestLoggingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public class RequestLoggingOptions
/// </summary>
public ILogger Logger { get; set; }

/// <summary>
/// Include the full URL query string in the <c>RequestPath</c> property
/// that is attached to request log events. The default is <c>false</c>.
/// </summary>
public bool IncludeQueryInRequestPath { get; set; }

/// <summary>
/// Constructor
/// </summary>
Expand Down
14 changes: 9 additions & 5 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>4.1.0</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<Authors>Microsoft;Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -24,13 +24,17 @@
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0' and '$(TargetFramework)' != 'netstandard2.1'">
<DefineConstants>$(DefineConstants);HOSTBUILDER</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions src/Serilog.AspNetCore/SerilogWebHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static class SerilogWebHostBuilderExtensions
/// <c>WriteTo.Providers()</c> configuration method, enabling other <see cref="ILoggerProvider"/>s to receive events. By
/// default, only Serilog sinks will receive events.</param>
/// <returns>The web host builder.</returns>
#if HOSTBUILDER
[Obsolete("Prefer UseSerilog() on IHostBuilder")]
#endif
public static IWebHostBuilder UseSerilog(
this IWebHostBuilder builder,
ILogger logger = null,
Expand Down Expand Up @@ -83,6 +86,9 @@ public static class SerilogWebHostBuilderExtensions
/// the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers. Specify
/// <c>true</c> to write events to all providers.</param>
/// <returns>The web host builder.</returns>
#if HOSTBUILDER
[Obsolete("Prefer UseSerilog() on IHostBuilder")]
#endif
public static IWebHostBuilder UseSerilog(
this IWebHostBuilder builder,
Action<WebHostBuilderContext, LoggerConfiguration> configureLogger,
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.AspNetCore.Tests/Serilog.AspNetCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using Serilog.Filters;
using Serilog.AspNetCore.Tests.Support;

// Newer frameworks provide IHostBuilder
#pragma warning disable CS0618

namespace Serilog.AspNetCore.Tests
{
public class SerilogWebHostBuilderExtensionsTests : IClassFixture<SerilogWebApplicationFactory>
Expand Down

0 comments on commit d0b616b

Please sign in to comment.