-
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.
- Loading branch information
1 parent
9e203e1
commit 6027b0c
Showing
10 changed files
with
76 additions
and
58 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
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
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
This file was deleted.
Oops, something went wrong.
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,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); | ||
} | ||
} |
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
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,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)); | ||
} |
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 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(); | ||
} | ||
} |