-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjusted Serilog configuration as provider
- Loading branch information
1 parent
f047798
commit 7e67b4a
Showing
5 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using DragonSpark.Model.Commands; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog.Extensions.Logging; | ||
using System; | ||
using ILogger = Serilog.ILogger; | ||
|
||
namespace DragonSpark.Diagnostics; | ||
|
||
sealed class AddProvider : ICommand<(HostBuilderContext Context, ILoggingBuilder Builder)> | ||
{ | ||
readonly Func<IConfiguration, ILogger> _logger; | ||
|
||
public AddProvider(Func<IConfiguration, ILogger> logger) => _logger = logger; | ||
|
||
public void Execute((HostBuilderContext Context, ILoggingBuilder Builder) parameter) | ||
{ | ||
var (context, builder) = parameter; | ||
var logger = _logger(context.Configuration); | ||
builder.AddProvider(new SerilogLoggerProvider(logger, true)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
using DragonSpark.Model.Commands; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Serilog; | ||
using DragonSpark.Compose; | ||
using DragonSpark.Model.Commands; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using ILogger = Serilog.ILogger; | ||
|
||
namespace DragonSpark.Diagnostics; | ||
|
||
sealed class ConfigureSerilog : ICommand<IServiceCollection> | ||
sealed class ConfigureSerilog : ICommand<IHostBuilder> | ||
{ | ||
readonly Func<IServiceCollection, ILogger> _logger; | ||
readonly Action<HostBuilderContext, ILoggingBuilder> _add; | ||
|
||
public ConfigureSerilog(Func<IServiceCollection, ILogger> logger) => _logger = logger; | ||
public ConfigureSerilog(Func<IConfiguration, ILogger> logger) : this(new AddProvider(logger).Execute) {} | ||
|
||
public void Execute(IServiceCollection parameter) | ||
public ConfigureSerilog(Action<HostBuilderContext, ILoggingBuilder> add) => _add = add; | ||
|
||
public void Execute(IHostBuilder parameter) | ||
{ | ||
var logger = _logger(parameter); | ||
parameter.AddLogging(new AddSerilog(logger).Execute); | ||
parameter.ConfigureLogging(_add); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
using DragonSpark.Compose; | ||
using DragonSpark.Composition; | ||
using DragonSpark.Model.Selection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Configuration; | ||
using Serilog; | ||
|
||
namespace DragonSpark.Diagnostics; | ||
|
||
sealed class DefaultLogger : Select<IServiceCollection, ILogger> | ||
sealed class DefaultLogger : Select<IConfiguration, ILogger> | ||
{ | ||
public static DefaultLogger Default { get; } = new(); | ||
|
||
DefaultLogger() : base(Start.A.Selection<IServiceCollection>() | ||
.By.Calling(x => x.Configuration()) | ||
.Select(CreateConfiguration.Default) | ||
.Select(CreateLogger.Default)) {} | ||
DefaultLogger() : base(CreateConfiguration.Default.Then().Select(CreateLogger.Default)) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters