Skip to content

Commit

Permalink
Basic Serilog support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo committed Jan 4, 2022
1 parent 6382e99 commit f047798
Show file tree
Hide file tree
Showing 87 changed files with 126 additions and 2,225 deletions.
18 changes: 18 additions & 0 deletions DragonSpark.Diagnostics/AddSerilog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using DragonSpark.Model.Commands;
using Microsoft.Extensions.Logging;
using Serilog;
using ILogger = Serilog.ILogger;

namespace DragonSpark.Diagnostics;

sealed class AddSerilog : ICommand<ILoggingBuilder>
{
readonly ILogger _logger;

public AddSerilog(ILogger logger) => _logger = logger;

public void Execute(ILoggingBuilder parameter)
{
parameter.AddSerilog(_logger, true);
}
}
19 changes: 19 additions & 0 deletions DragonSpark.Diagnostics/ConfigureSerilog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DragonSpark.Model.Commands;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System;

namespace DragonSpark.Diagnostics;

sealed class ConfigureSerilog : ICommand<IServiceCollection>
{
readonly Func<IServiceCollection, ILogger> _logger;

public ConfigureSerilog(Func<IServiceCollection, ILogger> logger) => _logger = logger;

public void Execute(IServiceCollection parameter)
{
var logger = _logger(parameter);
parameter.AddLogging(new AddSerilog(logger).Execute);
}
}
32 changes: 32 additions & 0 deletions DragonSpark.Diagnostics/CreateConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using DragonSpark.Model.Selection;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Enrichers.Correlation;

namespace DragonSpark.Diagnostics;

sealed class CreateConfiguration : ISelect<IConfiguration, LoggerConfiguration>
{
public static CreateConfiguration Default { get; } = new();

CreateConfiguration() {}

public LoggerConfiguration Get(IConfiguration parameter)
{
var instance = new LoggerConfiguration().Enrich.WithDemystifiedStackTraces()
.Enrich.WithEnvironmentName()
.Enrich.WithEnvironmentUserName()
.Enrich.FromLogContext()
.Enrich.WithProcessId()
.Enrich.WithProcessName()
.Enrich.WithMemoryUsage()
.Enrich.WithThreadId()
.Enrich.WithThreadName()
.Enrich.WithCorrelationId()
.Enrich.WithEnvironmentUserName()
.Enrich;
var result = EnvironmentLoggerConfigurationExtensions.WithMachineName(instance)
.ReadFrom.Configuration(parameter);
return result;
}
}
13 changes: 13 additions & 0 deletions DragonSpark.Diagnostics/CreateLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using DragonSpark.Model.Selection;
using Serilog;

namespace DragonSpark.Diagnostics;

sealed class CreateLogger : ISelect<LoggerConfiguration, ILogger>
{
public static CreateLogger Default { get; } = new();

CreateLogger() {}

public ILogger Get(LoggerConfiguration parameter) => parameter.CreateLogger();
}
17 changes: 17 additions & 0 deletions DragonSpark.Diagnostics/DefaultLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using DragonSpark.Compose;
using DragonSpark.Composition;
using DragonSpark.Model.Selection;
using Microsoft.Extensions.DependencyInjection;
using Serilog;

namespace DragonSpark.Diagnostics;

sealed class DefaultLogger : Select<IServiceCollection, ILogger>
{
public static DefaultLogger Default { get; } = new();

DefaultLogger() : base(Start.A.Selection<IServiceCollection>()
.By.Calling(x => x.Configuration())
.Select(CreateConfiguration.Default)
.Select(CreateLogger.Default)) {}
}
81 changes: 12 additions & 69 deletions DragonSpark.Diagnostics/DragonSpark.Diagnostics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,28 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Logging\Configuration\**" />
<EmbeddedResource Remove="Logging\Configuration\**" />
<None Remove="Logging\Configuration\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="ApplyProjectionsCommand.cs" />
<Compile Remove="ContextSelector.cs" />
<Compile Remove="DefaultLoggingLevel.cs" />
<Compile Remove="Exception.cs" />
<Compile Remove="ExceptionParameter.cs" />
<Compile Remove="Formats.cs" />
<Compile Remove="IFormats.cs" />
<Compile Remove="ILogMessage.cs" />
<Compile Remove="Implementations.cs" />
<Compile Remove="IPrimaryLogger.cs" />
<Compile Remove="IScalar.cs" />
<Compile Remove="IScalars.cs" />
<Compile Remove="Log.cs" />
<Compile Remove="LogException.cs" />
<Compile Remove="Logger.cs" />
<Compile Remove="LoggerDestructureSelector.cs" />
<Compile Remove="LoggerEnrichmentSelector.cs" />
<Compile Remove="LoggerSelector.cs" />
<Compile Remove="LoggerSinkDecoration.cs" />
<Compile Remove="LoggerSinkSelector.cs" />
<Compile Remove="Logging.cs" />
<Compile Remove="LoggingLevelController.cs" />
<Compile Remove="LogMessage.cs" />
<Compile Remove="Message.cs" />
<Compile Remove="PrimaryAssemblyEnricher.cs" />
<Compile Remove="PrimaryLogger.cs" />
<Compile Remove="ProjectionAwareSink.cs" />
<Compile Remove="ProjectionAwareSinkDecoration.cs" />
<Compile Remove="ProjectionEnricher.cs" />
<Compile Remove="ProjectionLogEvents.cs" />
<Compile Remove="PropertyFactories.cs" />
<Compile Remove="Scalar.cs" />
<Compile Remove="ScalarProperty.cs" />
<Compile Remove="Scalars.cs" />
<Compile Remove="SeqConfiguration.cs" />
<Compile Remove="TraceConfiguration.cs" />
</ItemGroup>
<PackageReference Include="Seq.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Serilog.Enrichers.Demystifier" Version="1.0.2" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.2.0" />

<ItemGroup>
<Compile Include="Logging\Configuration\DefaultLoggingConfiguration.cs" />
<Compile Include="Logging\Configuration\EnhancedExceptionStackTraceConfiguration.cs" />
<Compile Include="Logging\Configuration\EnrichmentConfiguration.cs" />
<Compile Include="Logging\Configuration\ILoggingConfiguration.cs" />
<Compile Include="Logging\Configuration\ILoggingEnrichmentConfiguration.cs" />
<Compile Include="Logging\Configuration\ILoggingSinkConfiguration.cs" />
<Compile Include="Logging\Configuration\LoggerConfigurations.cs" />
<Compile Include="Logging\Configuration\LoggingConfiguration.cs" />
<Compile Include="Logging\Configuration\LoggingLevelControllerConfiguration.cs" />
<Compile Include="Logging\Configuration\SinkConfiguration.cs" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Serilog.Enrichers.Context" Version="4.2.0" />
<PackageReference Include="Serilog.Enrichers.Correlation" Version="0.0.5" />
<PackageReference Include="Serilog.Enrichers.Demystify" Version="0.1.0-dev-00016" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
<PackageReference Include="Serilog.Enrichers.ExceptionStackTraceHash" Version="1.2.0" />
<PackageReference Include="Serilog.Enrichers.Correlation" Version="0.0.7" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Enrichers.ExceptionStackTraceHash" Version="1.3.0" />
<PackageReference Include="Serilog.Enrichers.Memory" Version="1.0.4" />
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.1" />
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.1-dev-00154" />
<PackageReference Include="Serilog.Sinks.Trace" Version="3.0.0-dev-00728" />
</ItemGroup>
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<!--<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />-->
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.0" />

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DragonSpark\DragonSpark.csproj" />
<ProjectReference Include="..\DragonSpark.Composition\DragonSpark.Composition.csproj" />
</ItemGroup>

</Project>
18 changes: 0 additions & 18 deletions DragonSpark.Diagnostics/DurableRetry.cs

This file was deleted.

13 changes: 0 additions & 13 deletions DragonSpark.Diagnostics/EnhancedExceptions.cs

This file was deleted.

43 changes: 0 additions & 43 deletions DragonSpark.Diagnostics/ExtensionMethods.cs

This file was deleted.

15 changes: 15 additions & 0 deletions DragonSpark.Diagnostics/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using DragonSpark.Composition.Compose;
using Microsoft.Extensions.DependencyInjection;
using System;
using ILogger = Serilog.ILogger;

namespace DragonSpark.Diagnostics;

public static class Extensions
{
public static BuildHostContext WithSerilog(this BuildHostContext @this)
=> @this.WithSerilog(DefaultLogger.Default.Get);

public static BuildHostContext WithSerilog(this BuildHostContext @this, Func<IServiceCollection, ILogger> logger)
=> @this.Configure(new ConfigureSerilog(logger));
}
9 changes: 0 additions & 9 deletions DragonSpark.Diagnostics/LinearRetryTime.cs

This file was deleted.

31 changes: 0 additions & 31 deletions DragonSpark.Diagnostics/LogRetryException.cs

This file was deleted.

37 changes: 0 additions & 37 deletions DragonSpark.Diagnostics/Logging/ApplyProjectionsCommand.cs

This file was deleted.

Loading

0 comments on commit f047798

Please sign in to comment.