-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
4 changed files
with
54 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Sitko.Core.App.Logging; | ||
|
||
public class BootLogger<T> : IBootLogger<T> | ||
{ | ||
private readonly ILogger<T> logger; | ||
private readonly IApplicationContext applicationContext; | ||
private readonly ILogger bootLogger; | ||
|
||
// ReSharper disable once ContextualLoggerProblem | ||
public BootLogger(ILogger<T> logger, IApplicationContext applicationContext, | ||
[FromKeyedServices("BootLogger")] ILogger bootLogger) | ||
{ | ||
this.logger = logger; | ||
this.applicationContext = applicationContext; | ||
this.bootLogger = bootLogger; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, | ||
Func<TState, Exception?, string> formatter) | ||
{ | ||
logger.Log(logLevel, eventId, state, exception, formatter); | ||
if (!applicationContext.IsDevelopment()) | ||
{ | ||
bootLogger.Log(logLevel, eventId, state, exception, formatter); | ||
} | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) => true; | ||
|
||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => logger.BeginScope(state); | ||
} |
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,7 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Sitko.Core.App.Logging; | ||
|
||
internal interface IBootLogger<out T> : ILogger<T> | ||
{ | ||
} |
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