Skip to content

Commit

Permalink
Warmup registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo committed Mar 14, 2024
1 parent 9e203e1 commit 6027b0c
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="8.1.5" />
<PackageVersion Include="Majorsoft.Blazor.Components.Common.JsInterop" Version="1.5.0" />
<PackageVersion Include="Majorsoft.Blazor.Components.Debounce" Version="1.5.0" />
<PackageVersion Include="Markdig" Version="0.35.0" />
<PackageVersion Include="Markdig" Version="0.36.0" />
<PackageVersion Include="MatBlazor" Version="2.10.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.3" />
Expand Down
3 changes: 3 additions & 0 deletions DragonSpark.Composition/Compose/BuildHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public BuildHostContext() : this(A.Self<IHostBuilder>()) {}

public BuildHostContext WithEnvironment(string name) => Select(new ConfigureEnvironment(name));

public BuildHostContext Configure(Action<IHostBuilder> configuration)
=> Configure(Start.A.Command<IHostBuilder>().By.Calling(configuration).Get());

public BuildHostContext Configure(ICommand<IHostBuilder> configuration)
=> Select(configuration.Then().ToConfiguration().Out());

Expand Down
13 changes: 11 additions & 2 deletions DragonSpark.Diagnostics/ConfigureSerilog.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using DragonSpark.Model.Commands;
using DragonSpark.Composition;
using DragonSpark.Model.Commands;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using SerilogTracing;
using System;
using ILogger = Serilog.ILogger;

namespace DragonSpark.Diagnostics;

Expand All @@ -13,6 +17,11 @@ sealed class ConfigureSerilog : ICommand<IServiceCollection>

public void Execute(IServiceCollection parameter)
{
parameter.AddScoped(_provider);
var configuration = new LoggerConfiguration().ReadFrom.Configuration(parameter.Configuration());
var logger = configuration.CreateLogger();
parameter.AddSingleton(new ActivityListenerConfiguration())
.AddSingleton(configuration)
.AddSingleton<ILogger>(logger)
.AddScoped(_provider);
}
}
24 changes: 0 additions & 24 deletions DragonSpark.Diagnostics/CreateConfiguration.cs

This file was deleted.

14 changes: 0 additions & 14 deletions DragonSpark.Diagnostics/CreateLogger.cs

This file was deleted.

15 changes: 13 additions & 2 deletions DragonSpark.Diagnostics/CreateLoggingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
using DragonSpark.Model.Selection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Core;
using Serilog.Extensions.Logging;
using System;
using System.Linq;
using ILogger = Serilog.ILogger;

namespace DragonSpark.Diagnostics;

sealed class CreateLoggingProvider : ISelect<ILogger, ILoggerProvider>
sealed class CreateLoggingProvider : ISelect<IServiceProvider, ILoggerProvider>
{
public static CreateLoggingProvider Default { get; } = new();

CreateLoggingProvider() {}

public ILoggerProvider Get(ILogger parameter) => new SerilogLoggerProvider(parameter, true);
public ILoggerProvider Get(IServiceProvider parameter)
{
var enrichers = parameter.GetServices<ILogEventEnricher>().ToArray();
parameter.GetRequiredService<LoggerConfiguration>().Enrich.With(enrichers);
var logger = parameter.GetRequiredService<ILogger>();
return new SerilogLoggerProvider(logger, true);
}
}
14 changes: 0 additions & 14 deletions DragonSpark.Diagnostics/DefaultLoggingProvider.cs

This file was deleted.

4 changes: 3 additions & 1 deletion DragonSpark.Diagnostics/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DragonSpark.Composition.Compose;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Configuration;
Expand All @@ -9,12 +10,13 @@ namespace DragonSpark.Diagnostics;
public static class Extensions
{
public static BuildHostContext WithSerilog(this BuildHostContext @this)
=> @this.WithSerilog(DefaultLoggingProvider.Default.Get);
=> @this.WithSerilog(CreateLoggingProvider.Default.Get);

public static BuildHostContext WithSerilog(this BuildHostContext @this,
Func<IServiceProvider, ILoggerProvider> provider)
=> @this.Configure(new ConfigureSerilog(provider));

[UsedImplicitly]
public static LoggerConfiguration WithFrameworkEnrichers(this LoggerEnrichmentConfiguration @this)
=> @this.With(PrimaryAssemblyEnricher.Default, AssemblyDeployInformationEnricher.Default);
}
22 changes: 22 additions & 0 deletions DragonSpark.Diagnostics/Trace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using DragonSpark.Model.Selection;
using Serilog;
using SerilogTracing;

namespace DragonSpark.Diagnostics;

public class Trace<T> : ISelect<T, Tracing>
{
readonly ActivityListenerConfiguration _configuration;
readonly ILogger _logger;
readonly string _template;

protected Trace(ActivityListenerConfiguration configuration, ILogger logger, string template)
{
_configuration = configuration;
_logger = logger;
_template = template;
}

public Tracing Get(T parameter)
=> new(_configuration.TraceTo(_logger), _logger.StartActivity(_template, parameter));
}
23 changes: 23 additions & 0 deletions DragonSpark.Diagnostics/Tracing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using SerilogTracing;
using System;

namespace DragonSpark.Diagnostics;

public readonly struct Tracing : IDisposable
{
readonly IDisposable _disposable;

public Tracing(IDisposable disposable, LoggerActivity activity)
{
Activity = activity;
_disposable = disposable;
}

public LoggerActivity Activity { get; }

public void Dispose()
{
Activity.Dispose();
_disposable.Dispose();
}
}

0 comments on commit 6027b0c

Please sign in to comment.