public void CanReverseDuckTypeILoggerProvider() { var loggerProvider = new DirectSubmissionLoggerProvider(_sink, _formatter, DirectSubmissionLogLevel.Debug); var proxyProvider = (ILoggerProvider)loggerProvider.DuckImplement(_iloggerProviderType); var logger = proxyProvider.CreateLogger("Some category"); logger.BeginScope(123).Should().NotBeNull(); logger.IsEnabled(LogLevel.Error).Should().BeTrue(); logger.Log(LogLevel.Error, "This is my message with a {Parameter}", 123); }
public void CanDuckTypeExternalScopeProviderAndUseWithProxyProvider() { var scopeProvider = new LoggerExternalScopeProvider(); var loggerProvider = new DirectSubmissionLoggerProvider(new NullDatadogSink(), LogSettingsHelper.GetFormatter(), DirectSubmissionLogLevel.Debug); var proxyProvider = (ISupportExternalScope)loggerProvider.DuckImplement(_iloggerProviderType); proxyProvider.SetScopeProvider(scopeProvider); var logger = loggerProvider.CreateLogger("Test logger name"); using var scope = logger.BeginScope(123); scope.Should().NotBeNull(); logger.IsEnabled(3).Should().BeTrue(); logger.Log(logLevel: 3, 12, state: 123, null, (state, ex) => $"This is my message with a {state}"); }