in src/Elastic.OpenTelemetry.Core/Diagnostics/StandardOutLogger.cs [10:35]
internal sealed class StandardOutLogger(CompositeElasticOpenTelemetryOptions options) : ILogger
{
private readonly LogLevel _configuredLogLevel = options.LogLevel;
private readonly LoggerExternalScopeProvider _scopeProvider = new();
private bool StandardOutLoggingEnabled { get; } = options.GlobalLogEnabled && options.LogTargets.HasFlag(LogTargets.StdOut);
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
return;
var logLine = LogFormatter.Format(logLevel, eventId, state, exception, formatter);
if (logLevel > LogLevel.Warning)
Console.Error.WriteLine(logLine);
else
Console.Out.WriteLine(logLine);
}
// We skip logging for any log level higher (numerically) than the configured log level
public bool IsEnabled(LogLevel logLevel) => StandardOutLoggingEnabled && _configuredLogLevel <= logLevel;
public IDisposable BeginScope<TState>(TState state) where TState : notnull => _scopeProvider.Push(state);
}