forked from open-telemetry/opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenTelemetrySdkExtensions.cs
More file actions
34 lines (30 loc) · 1.12 KB
/
OpenTelemetrySdkExtensions.cs
File metadata and controls
34 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using OpenTelemetry.Internal;
namespace OpenTelemetry;
/// <summary>
/// Contains methods for extending the <see cref="OpenTelemetrySdk"/> class.
/// </summary>
public static class OpenTelemetrySdkExtensions
{
/// <summary>
/// Gets the <see cref="ILoggerFactory"/> contained in an <see
/// cref="OpenTelemetrySdk"/> instance.
/// </summary>
/// <remarks>
/// Note: The default <see cref="ILoggerFactory"/> will be a no-op instance.
/// Call <see
/// cref="OpenTelemetryBuilderSdkExtensions.WithLogging(IOpenTelemetryBuilder)"/>
/// to enable logging.
/// </remarks>
/// <param name="sdk"><see cref="OpenTelemetrySdk"/>.</param>
/// <returns><see cref="ILoggerFactory"/>.</returns>
public static ILoggerFactory GetLoggerFactory(this OpenTelemetrySdk sdk)
{
Guard.ThrowIfNull(sdk);
return (ILoggerFactory?)sdk.Services.GetService(typeof(ILoggerFactory))
?? NullLoggerFactory.Instance;
}
}