| | 1 | | namespace Songhay.Extensions; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extensions of <see cref="TraceSources"/> |
| | 5 | | /// </summary> |
| | 6 | | public static class TraceSourcesExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Gets the configured trace source. |
| | 10 | | /// </summary> |
| | 11 | | /// <param name="instance">The instance.</param> |
| | 12 | | /// <remarks> |
| | 13 | | /// For .NET Standard, this member makes sense after lines like these: |
| | 14 | | /// <code> |
| | 15 | | /// var configuration = builder.Build(); |
| | 16 | | /// TraceSources.ConfiguredTraceSourceName = configuration[DeploymentEnvironment.DefaultTraceSourceNameConfigura |
| | 17 | | /// </code> |
| | 18 | | /// |
| | 19 | | /// This member makes the <c>GetConfiguredTraceSource</c> pattern cross platform. |
| | 20 | | /// </remarks> |
| | 21 | | public static TraceSource? GetConfiguredTraceSource(this TraceSources? instance) => |
| 8 | 22 | | instance.GetConfiguredTraceSource(configuration: null, key: null); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Gets the configured trace source. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="instance">The instance.</param> |
| | 28 | | /// <param name="configuration">The configuration.</param> |
| | 29 | | /// <remarks> |
| | 30 | | /// For .NET Standard, this member makes sense after lines like these: |
| | 31 | | /// <code> |
| | 32 | | /// var configuration = builder.Build(); |
| | 33 | | /// TraceSources.ConfiguredTraceSourceName = configuration[DeploymentEnvironment.DefaultTraceSourceNameConfigura |
| | 34 | | /// </code> |
| | 35 | | /// |
| | 36 | | /// This member makes the <c>GetConfiguredTraceSource</c> pattern cross platform. |
| | 37 | | /// </remarks> |
| | 38 | | public static TraceSource? GetConfiguredTraceSource(this TraceSources? instance, IConfiguration? configuration) => |
| 0 | 39 | | instance.GetConfiguredTraceSource(configuration, key: null); |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets the configured trace source. |
| | 43 | | /// </summary> |
| | 44 | | /// <param name="instance">The instance.</param> |
| | 45 | | /// <param name="configuration">The configuration.</param> |
| | 46 | | /// <param name="key">The key.</param> |
| | 47 | | /// <remarks> |
| | 48 | | /// For .NET Standard, this member makes sense after lines like these: |
| | 49 | | /// <code> |
| | 50 | | /// var configuration = builder.Build(); |
| | 51 | | /// TraceSources.ConfiguredTraceSourceName = configuration[DeploymentEnvironment.DefaultTraceSourceNameConfigura |
| | 52 | | /// </code> |
| | 53 | | /// |
| | 54 | | /// This member makes the <c>GetConfiguredTraceSource</c> pattern cross platform. |
| | 55 | | /// </remarks> |
| | 56 | | public static TraceSource? GetConfiguredTraceSource(this TraceSources? instance, IConfiguration? configuration, |
| | 57 | | string? key) |
| 10 | 58 | | { |
| 10 | 59 | | if (instance == null) return null; |
| | 60 | |
|
| 18 | 61 | | if (configuration == null) return instance.GetTraceSourceFromConfiguredName(); |
| | 62 | |
|
| 2 | 63 | | if (string.IsNullOrWhiteSpace(key)) key = DeploymentEnvironment.DefaultTraceSourceNameConfigurationKey; |
| 2 | 64 | | TraceSources.ConfiguredTraceSourceName = configuration[key]; |
| | 65 | |
|
| 2 | 66 | | return instance.GetTraceSourceFromConfiguredName(); |
| 10 | 67 | | } |
| | 68 | | } |