-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to pass log info to serilog without rendering the log statement (#…
…266) * Try to pass log info to serilog without rendering the log statement * formatting * remove redundant from new
- Loading branch information
1 parent
b086d16
commit 6115620
Showing
9 changed files
with
51 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 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,10 @@ | ||
using Serilog.Extensions.Logging; | ||
|
||
namespace Speckle.Connectors.Logging; | ||
|
||
public sealed class LoggerProvider(SerilogLoggerProvider provider) : IDisposable | ||
{ | ||
public Logger CreateLogger(string categoryName) => new(provider.CreateLogger(categoryName)); | ||
|
||
public void Dispose() => provider.Dispose(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,26 @@ | ||
using Serilog.Events; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Speckle.Connectors.Logging; | ||
|
||
public sealed class Logger | ||
public sealed class Logger(ILogger logger) | ||
{ | ||
private readonly Serilog.ILogger _logger; | ||
|
||
public Logger(Serilog.ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
private static LogEventLevel GetLevel(SpeckleLogLevel speckleLogLevel) => | ||
private static LogLevel GetLevel(SpeckleLogLevel speckleLogLevel) => | ||
speckleLogLevel switch | ||
{ | ||
SpeckleLogLevel.Debug => LogEventLevel.Debug, | ||
SpeckleLogLevel.Verbose => LogEventLevel.Verbose, | ||
SpeckleLogLevel.Information => LogEventLevel.Information, | ||
SpeckleLogLevel.Warning => LogEventLevel.Warning, | ||
SpeckleLogLevel.Error => LogEventLevel.Error, | ||
SpeckleLogLevel.Fatal => LogEventLevel.Fatal, | ||
SpeckleLogLevel.Debug => LogLevel.Debug, | ||
SpeckleLogLevel.Verbose => LogLevel.Trace, | ||
SpeckleLogLevel.Information => LogLevel.Information, | ||
SpeckleLogLevel.Warning => LogLevel.Warning, | ||
SpeckleLogLevel.Error => LogLevel.Error, | ||
SpeckleLogLevel.Fatal => LogLevel.Critical, | ||
_ => throw new ArgumentOutOfRangeException(nameof(speckleLogLevel), speckleLogLevel, null) | ||
}; | ||
|
||
public void Write(SpeckleLogLevel speckleLogLevel, string message, params object?[] arguments) => | ||
_logger.Write(GetLevel(speckleLogLevel), message, arguments); | ||
|
||
public void Write( | ||
public void Write<TState>( | ||
SpeckleLogLevel speckleLogLevel, | ||
int eventId, | ||
TState state, | ||
Exception? exception, | ||
string message, | ||
params object?[] arguments | ||
) => _logger.Write(GetLevel(speckleLogLevel), exception, message, arguments); | ||
|
||
public void Debug(string message, params object?[] arguments) => _logger.Debug(message, arguments); | ||
|
||
public void Debug(Exception? exception, string message, params object?[] arguments) => | ||
_logger.Debug(exception, message, arguments); | ||
|
||
public void Warning(string message, params object?[] arguments) => _logger.Warning(message, arguments); | ||
|
||
public void Warning(Exception? exception, string message, params object?[] arguments) => | ||
_logger.Warning(exception, message, arguments); | ||
|
||
public void Information(string message, params object?[] arguments) => _logger.Information(message, arguments); | ||
|
||
public void Information(Exception? exception, string message, params object?[] arguments) => | ||
_logger.Information(exception, message, arguments); | ||
|
||
public void LogError(string message, params object?[] arguments) => _logger.Error(message, arguments); | ||
|
||
public void LogError(Exception? exception, string message, params object?[] arguments) => | ||
_logger.Error(exception, message, arguments); | ||
|
||
public void Fatal(Exception? exception, string message, params object?[] arguments) => | ||
_logger.Fatal(exception, message, arguments); | ||
Func<TState, Exception?, string> formatter | ||
) => logger.Log(GetLevel(speckleLogLevel), new EventId(eventId), state, exception, formatter); | ||
} |
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