Skip to content

Commit

Permalink
Pass IHostApplicationBuilder instead of IConfiguration so that the Se…
Browse files Browse the repository at this point in the history
…rilog configuration method can have access to the environment in addition to the configuration.
  • Loading branch information
jonsagara committed Oct 22, 2023
1 parent 41fcf27 commit 76c7a89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>12.0</LangVersion>

<!-- NuGet -->
<Version>2.0.0-rc4</Version>
<Version>2.0.0-rc5</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Authors>Jon Sagara</Authors>
Expand Down
7 changes: 3 additions & 4 deletions src/Sagara.Core.Logging.Serilog/SerilogExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace Sagara.Core.Logging.Serilog;
Expand All @@ -23,13 +22,13 @@ public static class SerilogExtensions
/// registered through the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers.
/// Specify true to write events to all providers.</param>
/// <returns>The host application builder.</returns>
public static HostApplicationBuilder UseSerilog(this HostApplicationBuilder builder, Action<IConfiguration, IServiceProvider, LoggerConfiguration> configureLogger, bool preserveStaticLogger = false, bool writeToProviders = false)
public static IHostApplicationBuilder UseSerilog(this IHostApplicationBuilder builder, Action<IHostApplicationBuilder, IServiceProvider, LoggerConfiguration> configureLogger, bool preserveStaticLogger = false, bool writeToProviders = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configureLogger);

builder.Services.AddSerilog(
(serviceProvider, loggerConfiguration) => configureLogger(builder.Configuration, serviceProvider, loggerConfiguration),
(serviceProvider, loggerConfiguration) => configureLogger(builder, serviceProvider, loggerConfiguration),
preserveStaticLogger: preserveStaticLogger,
writeToProviders: writeToProviders
);
Expand Down

0 comments on commit 76c7a89

Please sign in to comment.