Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: serilog/serilog-extensions-hosting
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: cnblogs/cnblogs-serilog-extensions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 20 commits
  • 41 files changed
  • 1 contributor

Commits on Feb 11, 2023

  1. Copy the full SHA
    f36cba8 View commit details
  2. Merge pull request #1 from cnblogs/support-iloggingbuilder

    feat: support ILoggingBuilder
    cnblogs-dudu authored Feb 11, 2023
    Copy the full SHA
    88f431e View commit details
  3. Copy the full SHA
    1b80f93 View commit details
  4. Merge pull request #2 from cnblogs/support-net6-net7

    feat: support .NET 6 and .NET 7
    cnblogs-dudu authored Feb 11, 2023
    Copy the full SHA
    b8b56a1 View commit details
  5. ci: add github ci

    cnblogs-dudu committed Feb 11, 2023
    Copy the full SHA
    511be31 View commit details
  6. Merge pull request #3 from cnblogs/add-github-ci

    ci: add github ci
    cnblogs-dudu authored Feb 11, 2023
    Copy the full SHA
    874078a View commit details

Commits on Feb 12, 2023

  1. Copy the full SHA
    62bb7db View commit details
  2. Merge pull request #4 from cnblogs/move-addserilog-in-separate-class

    refactor: move AddSerilog to separate class
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    e88ec93 View commit details
  3. Copy the full SHA
    10c4e3e View commit details
  4. test: tweak test case

    cnblogs-dudu committed Feb 12, 2023
    Copy the full SHA
    4d786ff View commit details
  5. Copy the full SHA
    c59e75e View commit details
  6. Merge pull request #5 from cnblogs/add-more-extensions

    feat: add more extensions for ILoggingBuilder
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    149b53f View commit details
  7. build: add pack.sh

    cnblogs-dudu committed Feb 12, 2023
    Copy the full SHA
    ee95edf View commit details
  8. Merge pull request #6 from cnblogs/add-pack-script

    build: add pack.sh
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    46cdd0a View commit details
  9. Copy the full SHA
    85e4142 View commit details
  10. Merge pull request #7 from cnblogs/remove-hostbuilder-extensions

    refactor: remove SerilogHostBuilderExtensions
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    cf34ff0 View commit details
  11. Copy the full SHA
    8a47411 View commit details
  12. Merge pull request #8 from cnblogs/rename-project

    chore: rename Serilog.Extensions.Hosting to Cnblogs.Serilog.Extensions
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    74780bb View commit details
  13. Copy the full SHA
    8bbd6d3 View commit details
  14. Merge pull request #9 from cnblogs/add-new-hostbuilder-extensions

    feat: add new host builder extensions and remove netstandard support
    cnblogs-dudu authored Feb 12, 2023
    Copy the full SHA
    1513f85 View commit details
Showing with 722 additions and 602 deletions.
  1. +21 −0 .github/workflows/ci.yml
  2. +2 −10 build.sh
  3. +2 −2 serilog-extensions-hosting.sln → cnblogs-serilog-extensions.sln
  4. 0 serilog-extensions-hosting.sln.DotSettings → cnblogs-serilog-extensions.sln.DotSettings
  5. +0 −7 global.json
  6. +9 −0 pack.sh
  7. +6 −6 samples/SimpleServiceSample/Program.cs
  8. +5 −5 samples/SimpleServiceSample/SimpleServiceSample.csproj
  9. +4 −3 samples/WebApplicationSample/Program.cs
  10. +6 −6 samples/WebApplicationSample/WebApplicationSample.csproj
  11. +50 −0 src/Cnblogs.Serilog.Extensions/Cnblogs.Serilog.Extensions.csproj
  12. +1 −1 ...ons.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/AmbientDiagnosticContextCollector.cs
  13. +15 −14 ...og.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/CachingReloadableLogger.cs
  14. +5 −4 ...{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/DiagnosticContext.cs
  15. +7 −7 ...Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/DiagnosticContextCollector.cs
  16. +1 −1 ...ilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/FixedPropertyEnricher.cs
  17. +4 −2 ...{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/IReloadableLogger.cs
  18. +8 −7 ...log.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/InjectedLoggerSettings.cs
  19. +1 −1 src/{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/NullEnricher.cs
  20. +28 −27 src/{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/ReloadableLogger.cs
  21. +9 −8 ...rilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Extensions/Hosting/SerilogLoggerFactory.cs
  22. +2 −1 src/{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/IDiagnosticContext.cs
  23. +3 −6 src/{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/LoggerConfigurationExtensions.cs
  24. +2 −2 ...Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/LoggerSettingsConfigurationExtensions.cs
  25. 0 src/{Serilog.Extensions.Hosting → Cnblogs.Serilog.Extensions}/Properties/AssemblyInfo.cs
  26. +105 −0 src/Cnblogs.Serilog.Extensions/SerilogHostBuilderExtensions.cs.cs
  27. +270 −0 src/Cnblogs.Serilog.Extensions/SerilogLoggingBuilderExtensions.cs
  28. +0 −42 src/Serilog.Extensions.Hosting/Serilog.Extensions.Hosting.csproj
  29. +0 −255 src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs
  30. +2 −0 test.sh
  31. +52 −0 test/Cnblogs.Serilog.Extensions.Tests/Cnblogs.Serilog.Extensions.Tests.csproj
  32. +4 −6 test/{Serilog.Extensions.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/DiagnosticContextTests.cs
  33. +6 −6 ...s.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/LoggerSettingsConfigurationExtensionsTests.cs
  34. +19 −20 test/{Serilog.Extensions.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/ReloadableLoggerTests.cs
  35. +48 −0 test/Cnblogs.Serilog.Extensions.Tests/SerilogLoggingBuilderExtensionsTests.cs
  36. +3 −4 ...log.Extensions.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/Support/DisposeTrackingLogger.cs
  37. +1 −1 test/{Serilog.Extensions.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/Support/ListSink.cs
  38. +5 −8 test/{Serilog.Extensions.Hosting.Tests → Cnblogs.Serilog.Extensions.Tests}/Support/Some.cs
  39. +16 −0 test/Cnblogs.Serilog.Extensions.Tests/appsettings.json
  40. +0 −31 test/Serilog.Extensions.Hosting.Tests/Serilog.Extensions.Hosting.Tests.csproj
  41. +0 −109 test/Serilog.Extensions.Hosting.Tests/SerilogHostBuilderExtensionsTests.cs
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
container: mcr.microsoft.com/dotnet/sdk:7.0

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: ./build.sh
- name: Test
run: ./test.sh

12 changes: 2 additions & 10 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#!/bin/bash
dotnet --info
#!/usr/bin/env bash
dotnet restore

for path in src/**/*.csproj; do
dotnet build -f netstandard2.0 -c Release ${path}
done

for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp2.0 -c Release ${path}
done
dotnet build -c Release
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9
assets\Serilog.snk = assets\Serilog.snk
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Hosting", "src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj", "{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cnblogs.Serilog.Extensions", "src\Cnblogs.Serilog.Extensions\Cnblogs.Serilog.Extensions.csproj", "{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Hosting.Tests", "test\Serilog.Extensions.Hosting.Tests\Serilog.Extensions.Hosting.Tests.csproj", "{AD51759B-CD58-473F-9620-0B0E56A123A1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cnblogs.Serilog.Extensions.Tests", "test\Cnblogs.Serilog.Extensions.Tests\Cnblogs.Serilog.Extensions.Tests.csproj", "{AD51759B-CD58-473F-9620-0B0E56A123A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleServiceSample", "samples\SimpleServiceSample\SimpleServiceSample.csproj", "{E5A82756-4619-4E6B-8B26-6D83E00E99F0}"
EndProject
File renamed without changes.
7 changes: 0 additions & 7 deletions global.json

This file was deleted.

9 changes: 9 additions & 0 deletions pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

[ -z $1 ] && echo "Missing version" && exit 1

version=$1
project=src/Cnblogs.Serilog.Extensions
dotnet build -p:Version=${version-*} -c Release $project
dotnet pack $project -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --include-source -p:PackageVersion=$version -p:Version=${version-*} -o ./artifacts
12 changes: 6 additions & 6 deletions samples/SimpleServiceSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Cnblogs.Serilog.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using System;

namespace SimpleServiceSample
{
@@ -36,9 +36,9 @@ public static int Main(string[] args)
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddHostedService<PrintTimeService>())
.UseSerilog((context, services, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(context.Configuration)
.AddSerilog((conf, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(conf)
.Enrich.FromLogContext()
.WriteTo.Console());
}
}
}
10 changes: 5 additions & 5 deletions samples/SimpleServiceSample/SimpleServiceSample.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj" />
<ProjectReference Include="..\..\src\Cnblogs.Serilog.Extensions\Cnblogs.Serilog.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions samples/WebApplicationSample/Program.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cnblogs.Serilog.Extensions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
@@ -17,7 +18,7 @@ public static int Main(string[] args)
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();

Log.Information("Starting up!");

try
@@ -40,9 +41,9 @@ public static int Main(string[] args)

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((context, services, configuration) => configuration
.AddSerilog((conf, services, loggerConfig) => loggerConfig
.WriteTo.Console()
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Configuration(conf)
.ReadFrom.Services(services))
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
12 changes: 6 additions & 6 deletions samples/WebApplicationSample/WebApplicationSample.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Extensions.Hosting\Serilog.Extensions.Hosting.csproj" />
<ProjectReference Include="..\..\src\Cnblogs.Serilog.Extensions\Cnblogs.Serilog.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="serilog.settings.configuration" Version="3.1.0" />
<PackageReference Include="serilog.sinks.console" Version="3.1.1" />
<PackageReference Include="serilog.sinks.file" Version="4.1.0" />
<PackageReference Include="serilog.settings.configuration" Version="3.4.0" />
<PackageReference Include="serilog.sinks.console" Version="4.1.0" />
<PackageReference Include="serilog.sinks.file" Version="5.0.0" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions src/Cnblogs.Serilog.Extensions/Cnblogs.Serilog.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Extensions for Serilog</Description>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Cnblogs.Serilog.Extensions</AssemblyName>
<SignAssembly>true</SignAssembly>
<PackageId>Cnblogs.Serilog.Extensions</PackageId>
<PackageTags>serilog;logging</PackageTags>
<PackageProjectUrl>https://github.com/cnblogs/cnblogs-serilog-extensions</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cnblogs/cnblogs-serilog-extensions</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<RootNamespace>Cnblogs.Serilog.Extensions</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);NO_RELOADABLE_LOGGER</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
</ItemGroup>

<Choose>
<When Condition="'$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
using System;
using System.Threading;

namespace Serilog.Extensions.Hosting
namespace Cnblogs.Serilog.Extensions
{
class AmbientDiagnosticContextCollector : IDisposable
{
Original file line number Diff line number Diff line change
@@ -17,17 +17,18 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Serilog;
using Serilog.Core;
using Serilog.Events;

namespace Serilog.Extensions.Hosting
namespace Cnblogs.Serilog.Extensions
{
class CachingReloadableLogger : ILogger, IReloadableLogger
{
readonly ReloadableLogger _reloadableLogger;
readonly Func<ILogger, ILogger> _configure;
readonly IReloadableLogger _parent;

ILogger _root, _cached;
bool _frozen;

@@ -49,14 +50,14 @@ public ILogger ReloadLogger()
public ILogger ForContext(ILogEventEnricher enricher)
{
if (enricher == null) return this;

if (_frozen)
return _cached.ForContext(enricher);

if (_reloadableLogger.CreateChild(
_root,
this,
_cached,
_cached,
p => p.ForContext(enricher),
out var child,
out var newRoot,
@@ -72,14 +73,14 @@ public ILogger ForContext(ILogEventEnricher enricher)
public ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
{
if (enrichers == null) return this;

if (_frozen)
return _cached.ForContext(enrichers);

if (_reloadableLogger.CreateChild(
_root,
this,
_cached,
_cached,
p => p.ForContext(enrichers),
out var child,
out var newRoot,
@@ -95,7 +96,7 @@ public ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers)
public ILogger ForContext(string propertyName, object value, bool destructureObjects = false)
{
if (propertyName == null) return this;

if (_frozen)
return _cached.ForContext(propertyName, value, destructureObjects);

@@ -126,7 +127,7 @@ public ILogger ForContext(string propertyName, object value, bool destructureObj
return this;

var enricher = new FixedPropertyEnricher(property);

if (_reloadableLogger.CreateChild(
_root,
this,
@@ -148,11 +149,11 @@ public ILogger ForContext<TSource>()
{
if (_frozen)
return _cached.ForContext<TSource>();

if (_reloadableLogger.CreateChild(
_root,
this,
_cached,
_cached,
p => p.ForContext<TSource>(),
out var child,
out var newRoot,
@@ -173,7 +174,7 @@ public ILogger ForContext(Type source)
if (_reloadableLogger.CreateChild(
_root,
this,
_cached,
_cached,
p => p.ForContext(source),
out var child,
out var newRoot,
@@ -190,7 +191,7 @@ void Update(ILogger newRoot, ILogger newCached, bool frozen)
{
_root = newRoot;
_cached = newCached;

// https://github.com/dotnet/runtime/issues/20500#issuecomment-284774431
// Publish `_cached` and then `_frozen`. This is useful here because it means that once the logger is frozen - which
// we always expect - reads don't require any synchronization/interlocked instructions.
@@ -486,7 +487,7 @@ public bool IsEnabled(LogEventLevel level)

return isEnabled;
}

public bool BindMessageTemplate(string messageTemplate, object[] propertyValues, out MessageTemplate parsedTemplate,
out IEnumerable<LogEventProperty> boundProperties)
{
@@ -542,4 +543,4 @@ public bool BindProperty(string propertyName, object value, bool destructureObje
}
}

#endif
#endif
Original file line number Diff line number Diff line change
@@ -12,18 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Serilog;
using System;
using System.Threading;

namespace Serilog.Extensions.Hosting
namespace Cnblogs.Serilog.Extensions
{
/// <summary>
/// Implements an ambient diagnostic context using <see cref="AsyncLocal{T}"/>.
/// </summary>
/// <remarks>Consumers should use <see cref="IDiagnosticContext"/> to set context properties.</remarks>
public sealed class DiagnosticContext : IDiagnosticContext
{
readonly ILogger _logger;
private readonly ILogger _logger;

/// <summary>
/// Construct a <see cref="DiagnosticContext"/>.
@@ -50,7 +51,7 @@ public void Set(string propertyName, object value, bool destructureObjects = fal
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));

var collector = AmbientDiagnosticContextCollector.Current;
if (collector != null &&
if (collector != null &&
(_logger ?? Log.Logger).BindProperty(propertyName, value, destructureObjects, out var property))
{
collector.AddOrUpdate(property);
@@ -64,4 +65,4 @@ public void SetException(Exception exception)
collector?.SetException(exception);
}
}
}
}
Loading